Does anyone know why I cannot change an attribute when a player touches a part?
I am currently trying to make a game that lets the player switch between being a ghost and a person, and when the player spawns (touches the spawn point), the code below sets the attribute “ghost” to false.
function onTouch(part)
humanoid = part.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid.Parent:SetAttribute("Ghost", false)
end
end
script.Parent.Touched:connect(onTouch)
The killbrick only kills players with the “ghost” attribute set to false.
(Killbrick code below)
function onTouch(part)
humanoid = part.Parent:FindFirstChild("Humanoid")
if humanoid then
local ghost = humanoid.Parent:GetAttribute("Ghost")
if ghost == false then
humanoid.Health = 0
end
end
end
script.Parent.Touched:connect(onTouch)
Lastly, this part should change a player’s “ghost” attribute to true when they touch it. However, it is not able to do so as the killbrick can still kill the player.
(Code below)
function onTouch(part)
humanoid = part.Parent:FindFirstChild("Humanoid")
if humanoid then
local ghost = humanoid.Parent:GetAttribute("Ghost")
if ghost == false then
ghost = true
end
end
end
script.Parent.Touched:connect(onTouch)
I have checked that the killbrick works properly (setting “ghost” to true when player touches spawn makes the killbrick not do anything, so it is likely the last script that does not function.
Thank you for reading this!