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)
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.
4 comments
This won't work in a local script because 1. local scripts run only client side or you can simply call it "a script run only by players" and in this case the player doesn't do anything 2. the else statement must be inside of the if statement, it should be like "if X then something happens else something else happens" if that makes sense
not at all
it will work in a local script since the actions r being done on the client side so ur comment is not correct
Local scripts DO NOT work outside of playergui, backpack, playerscripts, replicated first and player's character. If you are new into this, it makes sense not to know this hence a lot of ppl new to it think that its fine to put local scripts everywhere. You can't even use this method to fire a remote event even though local scripts are the only way to fire a remote event.