✓ Accepted answer
Hi there,
Your game seems to be filtering enabled, and thus does not work in the actual game. As local scripts act like server scripts in studio, they will not turn out an error. However, in game, local scripts act like local scripts (local scripts can't access Server services such as what you are trying to access:Workspace) and only run on the client.
And thankfully, your script does not require that you use a local script. However in the future, if you'd like to know more about server script to client script communication, you may want to read this: http://wiki.roblox.com/index.php?title=Remote_Events_and_Functions
So, in your script, you will not have to get the local player but instead get the touched part's parent which is the player who touches the part. Instead of getting the player, you can find for the the player's name in game.Players or use GetPlayerFromCharacter(). Here's how your script should look like.
In a normal script:
local debounce = false
game.Workspace.Throne.Part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') then
if not debounce then
debounce = true
while hit.Parent.Humanoid.Health > 0 do
local player = hit.Parent.GetPlayerFromCharacter()
player:WaitForChild('leaderstats').Money.Value = player.leaderstats.Money.Value + 10
wait(5)
end
wait(2)
debounce = false
end
end
end)
Note:GetPlayerFromCharacter() may sometimes not work if so, try this script instead:
local debounce = false
game.Workspace.Throne.Part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') then
if not debounce then
debounce = true
while hit.Parent.Humanoid.Health > 0 do
local player = game.Players:FindFirstChild(hit.Parent.Name)
player:WaitForChild('leaderstats').Money.Value = player.leaderstats.Money.Value + 10
wait(5)
end
wait(2)
debounce = false
end
end
end)
2 comments
is this in a "Local Script" or "Script"?
He should be since it works in studio, and since he is using localplayer.