I have a script that teleport player back to spawn (using loadcharacter) and reward 100 cash when a player touch a part This is my script:
local Debounce = false
script.Parent.Touched:connect(function(hit)
if Debounce == false then
Debounce = true
if hit.Parent.Humanoid ~=nil then
print("touched")
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 100
player:LoadCharacter()
workspace.MapChanger.Waittime.Value = workspace.MapChanger.Waittime.Value /2
wait(5)
Debounce = false
end
end
end)
sometime when a player touch it, it give me an error saying Humanoid is not a valid player of Accessory then the script stop working... How can i prevent that?
Sorry for my bad english :(

3 comments
My script now print red color error line (without "It error :(") with a green line left to it.....Is that normal?
If that happen then you do it right. The green line left to it show is that line print by client or server(green mean server, blue mean client), and the red color error line is the ErrorMessage that you just print.
why it doesn't print without it error :( while i told it to?