function getPlayer(humanoid)
-- find the owning player of a humanoid. this is a hack and i don't know why i need it, game.Players.LocalPlayer didn't work
local players = game.Players:children()
for i = 1, #players do
if players[i].Character.Humanoid == humanoid then return players[i] end
end
return nil
end
function addPower(humanoid)
local player = getPlayer(humanoid)
-- Touching only happens client-side
if player == nil then return end
local stats = player:findFirstChild("leaderstats")
if stats == nil then return end
local power_tag = stats:findFirstChild("Gold")
if power_tag ~= nil then
power_tag.Value = power_tag.Value -10
end
end
function onTouched(part)
local parent = part.Parent
if parent~=nil then
local humanoid = parent:findFirstChild("Humanoid", false)
if humanoid ~= nil then
addPower(humanoid)
end
end
end
script.Parent.Touched:connect(onTouched)