Hello. I’ve got this code here where a gui is supposed to enable whenever the “killer” is within the distance of 10 of a “worker”
The Code:
local inputservice = game:GetService("UserInputService")
local rss = game:GetService('RunService')
local rs = game:GetService('ReplicatedStorage')
local Plrs = game:GetService('Players'):GetPlayers()
local xx = 0
local WithinDistanceKill = false
while true do
for i,Door in pairs(Plrs) do
if game.Players.LocalPlayer:FindFirstChild('PlayerCriticalInformation').KillerIntValue.Value == true and Door:FindFirstChild('PlayerCriticalInformation'):FindFirstChild('WorkerIntValue').Value == true and Door.Character:FindFirstChild('Humanoid').Health ~= 0 and game.Players.LocalPlayer:FindFirstChild('PlayerCriticalInformation'):FindFirstChild('CanKill').Value == true then
local Mag = (Door.Character.HumanoidRootPart.Position - game.Players.LocalPlayer.Character.HumanoidRootPart.Position).Magnitude
if Mag <= 10 and WithinDistanceKill == false then
WithinDistanceKill = true
game.Players.LocalPlayer.PlayerGui.KillGui.Enabled = true
inputservice.InputBegan:connect(function(i,g)
if not g then
if i.KeyCode == Enum.KeyCode.E then
for ii,Door1 in pairs(Plrs) do
if WithinDistanceKill == true and Door1.Name ~= game.Players.LocalPlayer.Name and Door1.Character.Humanoid.Health ~= 0 and game.Players.LocalPlayer:FindFirstChild('PlayerCriticalInformation'):FindFirstChild('CanKill').Value == true then
game.Players.LocalPlayer:FindFirstChild('PlayerCriticalInformation'):FindFirstChild('CanKill').Value = false
rs.InGame.KillEvent:FireServer(Door1)
game.Players.LocalPlayer.PlayerGui.KillGui.Enabled = false
WithinDistanceKill = false
wait(10)
game.Players.LocalPlayer:FindFirstChild('PlayerCriticalInformation'):FindFirstChild('CanKill').Value = true
end
end
end
end
end)
elseif Mag > 10 and WithinDistanceKill == true then
WithinDistanceKill = false
game.Players.LocalPlayer.PlayerGui.KillGui.Enabled = false
end
end
end
wait()
end
Now it does work, but not for every player.
Problem Vid
As you can see, the GUI shows up for one player, but not the other. They have the same values, so it isn’t that type of problem.
Just wondering where I went wrong. I’m assuming it’s something to do with the for loop with the Plrs.
Any help is appreciated!