Hi! I have a remote event that gets fired when u click a button, then through a server script i loop for each player and check their userId. If their UserId isn’t -1, an Instance is created with their name. The problem is that it creates like 1 instance for each player there is but all with the same name. Also when I then destroy the value created in the same script it deletes both of them. This is my code:
game:GetService("ReplicatedStorage"):WaitForChild("StartGame").OnServerEvent:Connect(function(plr, maxPlrs)
for i,v in pairs(game:GetService("Players"):GetChildren()) do
if v.UserId ~= -1 then
local value = Instance.new("BoolValue")
value.Parent = game:GetService("ReplicatedStorage"):WaitForChild("PlayersInGame")
value.Name = v.Name
value.Value = false
wait(5)
value:Destroy()
local slot = game:GetService("Workspace"):WaitForChild("Game"):WaitForChild("Slots"):WaitForChild("Slot"..current)
local cframe = Vector3.new(slot.Position.X, slot.Position.Y + 5, slot.Position.Z)
v.Character.HumanoidRootPart.CFrame = CFrame.new(cframe, game:GetService("Workspace"):WaitForChild("Game"):WaitForChild("EndPart").Position)
v.Character.Humanoid.WalkSpeed = 0
current += 1
game:GetService("ReplicatedStorage"):WaitForChild("PlayersPlaying").Value += 1
else
local slot = game:GetService("Workspace"):WaitForChild("Game"):WaitForChild("EndPart")
v.Character.HumanoidRootPart.CFrame = CFrame.new(slot.CFrame.X, slot.CFrame.Y + 5, slot.CFrame.Z)
end
end
end)
If there are 2 players playing, the folder looks like this: