✓ Accepted answer
I'm thinking your problem is..."player" is the player stored in game.Players and touched is the part that touched the detector (the players foot). You need detect if the part that is touching the detector is the players character. You then need to get the player instance from the players character(if you use that to compare).
You can do this like so...
game.Players.PlayerAdded:Connect(function(player)
script.Parent.Touched:Connect(function(hit)
local playerhit = game.Players:GetPlayerFromCharacter(hit.Parent)
if playerhit then
print("Hi there")
end
end)
end)
Sorry, not the greatest at explaining things so here's some documentation:
https://developer.roblox.com/en-us/api-reference/function/Players/GetPlayerFromCharacter
Edit:
You also need to change your variable set up. Doing it like this
local hp = script.Parent.Part1 and script.Parent.Part2 and script.Parent.Part3
will only change properties for part3
I recommend setting it up like this
local hp,bh,tp = script.Parent.Part1,script.Parent.Part2,script.Parent.Part3
or iterate through a model
local model = script.Parent
for i,v in pairs(model)do
if v:IsA("Part")then
v.Anchored = false
end
end
Please do upvote if this helped ;)
1 comment
thank you so much!