So I made a thing where if a player joins the map, they’re assigned to a plot. I tried testing it with multiple player’s through studio’s own testing thing, but it doesn’t seem to be working.
This is my script in serverscriptservice:
local plrs = game:GetService("Players")
plrs.PlayerAdded:Connect(function(plr)
for i,v in pairs(workspace.Plots:GetChildren()) do
if v:FindFirstChild("plr").Value ~= nil then continue end
print(v)
v:FindFirstChild("plr").Value = plr
v.sign.Text.SurfaceGui.TextLabel.Text = plr.Name
local chr = plr.Character or plr.CharacterAdded:Wait()
task.wait()
chr.HumanoidRootPart.CFrame = v:FindFirstChild("Spawn").CFrame
break
end
end)
Here is my new code. I tried testing with players, but they don’t spawn on their plot, they spawn in the middle of the map.
local plrs = game:GetService("Players")
plrs.PlayerAdded:Connect(function(plr)
for i,v in pairs(workspace.Plots:GetChildren()) do
if v:FindFirstChild("plr").Value ~= nil then continue end
print(v)
v:FindFirstChild("plr").Value = plr
v.sign.Text.SurfaceGui.TextLabel.Text = plr.Name
local chr = plr.Character or plr.CharacterAdded:Wait()
task.wait()
chr.HumanoidRootPart.CFrame = v:FindFirstChild("Spawn").CFrame
break
end
end)
plrs.PlayerRemoving:Connect(function(plr)
for i,v in pairs(workspace.Plots:GetChildren()) do
if v:FindFirstChild("plr").Value == nil then continue end
local owned_by = v:FindFirstChild("plr").Value
if owned_by == plr then
v:FindFirstChild("plr").Value = nil
v.sign.Text.SurfaceGui.TextLabel.Text = "Unclaimed"
break
end
end
end)
Try this code,
instead of setting the character’s HumanoidRootPart CFrame to “Spawn” part CFrame you need to set the character’s HumanoidRootPart CFrame to a new CFrame from “Spawn” part’s position.
plrs.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function()
for i,v in pairs(workspace.Plots:GetChildren()) do
if v:FindFirstChild("plr").Value ~= nil then continue end
print(v)
v:FindFirstChild("plr").Value = plr
v.sign.Text.SurfaceGui.TextLabel.Text = plr.Name
local chr = plr.Character or plr.CharacterAdded:Wait()
task.wait()
chr.HumanoidRootPart.CFrame = CFrame.new(v:FindFirstChild("Spawn").Position)
break
end
end)
end)
plrs.PlayerRemoving:Connect(function(plr)
for i,v in pairs(workspace.Plots:GetChildren()) do
if v:FindFirstChild("plr").Value == nil then continue end
local owned_by = v:FindFirstChild("plr").Value
if owned_by == plr then
v:FindFirstChild("plr").Value = nil
v.sign.Text.SurfaceGui.TextLabel.Text = "Unclaimed"
break
end
end
end)