Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does this automatically kill a player when walking up to them instead of pressing F?

Asked by 6 years ago

Sorry about the title being long but I had to ask it fully.

Essentially wondering why this code is killing any player the killer walks up to automatically. It should only kill the player the killer is near when pressing F. Of course though, it only starts to do that AFTER you kill a player once, not before killing anyone.

If anyone is capable of assisting and getting this code fixed, I'd appreciate it.

EXTRA CODE: (this is the part of the code that is binded by contextservice for killing the players, yes this game is FE and this is vital)

function KillPlayer()
    game.ReplicatedStorage.RequestKilling:FireServer(tostring(playertokill))
    playertokill = ""
    script.Parent.Hint.Visible = false
end

MAIN CODE: (this is the part of the code you'll have to pay attention to)

function YouAreKiller()
    while game.Players.LocalPlayer.Character.Torso ~= nil do
        for i,v in ipairs(game.Players:GetChildren()) do
            if tostring(v.Name) ~= tostring(game.Players.LocalPlayer.Name) then
                for j,b in ipairs(workspace.Survivors:GetChildren()) do
                    local player = game.Workspace:FindFirstChild(b.Name)

                    if player then
                        if playertokill ~= "" then
                            if (game.Workspace:FindFirstChild(tostring(playertokill)).Torso.Position - game.Players.LocalPlayer.Character.Torso.Position).magnitude >= 5 then
                                controls:UnbindAction("Kill")
                                script.Parent.Hint.Visible = false
                                playertokill = ""
                            end
                        elseif playertokill == "" then
                            if (v.Character.Torso.Position - game.Players.LocalPlayer.Character.Torso.Position).magnitude <= 4 then
                                playertokill = tostring(v.Name)
                                controls:BindAction("Kill", KillPlayer, false, Enum.KeyCode.F)
                                script.Parent.Hint.Visible = true
                            end
                        end
                    end
                end
            end
        end
        wait()
    end
end

also this is an actual game I am working on and plan to release, whoever DOES manage to fix this, I may reward a gift. as far as I know, I am currently lost on how to fix this issue.

Answer this question