local script inside part:
script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player.leaderstats.Rank.Value >= 5 then hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health end else hit.Parent.Humanoid.Health = 0 end end)
i get no errors
``` script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player.leaderstats.Rank.Value >= 5 then hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health else hit.Parent.Humanoid.Health = 0 -- you placed it in the wrong statement end else -- hit.Parent.Humanoid.Health = 0 end
end) ```
Its not possible to use local scripts outside of playergui, backpack, playerscripts, replicated first and player's character and expected them to do the job. If you want to do the job you have 2 options. Option 1: Put this in a regular script
script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player.leaderstats.Rank.Value < 5 then hit.Parent:FindFirstChild("Humanoid"):TakeDamage(100) --- or you could use hit.Parent:FindFistChild("Humanoid").Health = 0 as well end end end)
Option2: Create a remote event in ReplicatedStorage then add a normal script in the brick or whatever you want to touch
script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then hit.Parent:FindFirstChild("LocalScript").Disabled = false wait() hit.Parent:FindFirstChild("LocalScript").Disabled = true end end)
then make sure that you have a localscript inside of the player's character with this code:
while wait() do game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent"):FireServer() end
also make sure that the local script is set to disabled
then make a regular script inside of ServerScriptService with the code:
local repstorage = game:GetService("ReplicatedStorage") local kill = repstorage:WaitForChild("RemoteEvent") kill.OnServerEvent:Connect(function(plr) if plr.leaderstats.Rank.Value < 5 then plr.Character.Humanoid:TakeDamage(100) end end)
What the 2nd option does is that when a player touches the object it will turn on a local script inside of the player which will fire the remote event which will kill the player. There are probably other ways to do this as well but can't think of anything atm.