local seat = script.Parent local name_value = script.Parent.Parent.Name_Valu seat.Touched:connect(function(hit) name_value.Value = hit.Parent.Name print(name_value.Value) end) local debounce = false local seat = script.Parent local name_value = seat.Parent.Name_Valu seat.Touched:connect(function(hit) if not debounce then debounce = true if hit.Parent.Name == name_value.Value then local hum = hit.Parent:FindFirstChild("Humanoid") if hum ~= nil then hum.Health = hum.Health end else local hum = hit.Parent:FindFirstChild("Humanoid") if hum ~= nil then hum.Health = 0 end end debounce = false print(name_value.Value) end end)
You have a few problems wrong with your script here, I've outlined them with comments for easier, briefer communication. If you've caught any problems with my script then please do let me know.. nobody is a perfect coder!
It isn't very clear what you mean when you say the problem is caused "because of accessories", but I'll assume its because you aren't doing proper Humanoid checks to make sure "name_value" only becomes the name of the player and not whatever touches it.
Hope this helps.
ORIGINAL:
local seat = script.Parent -- * Why did you define "seat" twice? local name_value = script.Parent.Parent.Name_Valu -- ** seat.Touched:connect(function(hit) -- *** :connect() is deprecated, use :Connect() instead, also please don't define two of the same functions for the same object name_value.Value = hit.Parent.Name -- You need another check here to see if it was a player that hit the seat and not just some regular part print(name_value.Value) end) local debounce = false local seat = script.Parent local name_value = seat.Parent.Name_Valu -- ** "name_value" defined twice seat.Touched:connect(function(hit) -- *** if not debounce then debounce = true if hit.Parent.Name == name_value.Value then local hum = hit.Parent:FindFirstChild("Humanoid") -- ***** if hum ~= nil then hum.Health = hum.Health -- **** This is completely redundant end else local hum = hit.Parent:FindFirstChild("Humanoid") -- ***** "hum" defined twice, also the hum check should have been be handled earlier on to avoid problems if hum ~= nil then hum.Health = 0 end end debounce = false -- ****** Debounce becomes redundant if you don't have a wait(time). Regardless, this script doesn't need debounce because it only runs once once (when the player touches the seat) print(name_value.Value) end end)
EDITED:
local name_value = script.Parent.Parent.Name_Valu.Value script.Parent.Touched:Connect(function(hit) local hum = hit.Parent:FindFirstChild("Humanoid") if hum then if name_value == nil then name_value = hit.Parent.Name elseif name_value and hit.Parent.Name ~= name_value then hum.health = 0 end end end)