✓ Accepted answer
That's because you are trying to find an object named 'player' inside the Players service, which doesn't exist. Additionally, the returned object isn't a player, it's the part that touched. Since the part that touched it can be a limb of a player, we can use the method GetPlayerFromCharacter checking if the parent of the part (the potential character model) has a player.
(On a smaller note, connect is deprecated. Please use Connect.)
function onTouched(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
end
end
script.Parent.Touched:Connect(onTouched)
Also try to fix that formatting up a little bit. Your code needs to be neat and organized, otherwise you won't understand it.
4 comments
Are you that desperate for reputation lol.
... WHAT? Answering a person's question is making you desperate for reputation now?
lol you edited the part that said 'if this answered your question please mark it as answered and upvote it!'
What's wrong with saying that?