This should work for all players:
local part = script.Parent
local debounce = true
part.Touched:Connect(function(tch)
if tch and tch.Parent and game:GetService("Players"):GetPlayerFromCharacter(tch.Parent) and debounce == true then then
debounce = false
local human = tch.Parent:FindFirstChildOfClass("Humanoid")
if human then
human.Health = human.Health - math.random(1, 10)
else
print("Humanoid Does Not Exist")
end
wait(10)
debounce = true
end
end)
I'm using the GetPlayerFromCharacter(character) function of the Players Service to make sure that the object touched is from a player in the game
I'm using the FindFirstChildOfClass(ClassName) function to make sure you are accurately finding the Humanoid, as you may have changed the name of it.
The debounce is since you have a wait(10) I assume you only want this to run every 10 seconds.
1 comment
That code should work for a normal Roblox avatar. Have you put anything inside the character model that might create a naming conflict? Try printing out what typeof(tch.Parent) and typeof(tch.Parent.Humanoid) are, or their .ClassName properties. If they aren't both Instance types with Model and Humanoid class, something's amiss.