Still have questions? Join our Discord server and get real time help.
0

Why doesnt my script kill the player if rank is too low?

local script inside part:

script.Parent.Touched:Connect(function(hit)

if hit.Parent:FindFirstChild("Humanoid") then

local player = game.Players:GetPlayerFromCharacter(hit.Parent)

hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health

end

else

hit.Parent.Humanoid.Health = 0

end

end)


i get no errors

0
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 richboifexekappa 42 — 9d
0
not at all Gameplayer365247v2 166 — 9d
0
it will work in a local script since the actions r being done on the client side so ur comment is not correct Gameplayer365247v2 166 — 9d
0
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. richboifexekappa 42 — 9d

0

 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) 

0
indent your code it makes it easier to read unsatisfie_d 1401 — 10d
0
this script didnt work Gameplayer365247v2 166 — 10d
0

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)
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)