So this is the script that's in each spawn in my game. I ONLY want one player to spawn from each spawn. This script seems to not work. Anyone knows how to fix this?
function onTouch(part) --Finding Humanoid is useless... Max players = (1) part.Parent:findFirstChild("Head").CanCollide = true part.Parent:findFirstChild("Torso").CanCollide = true part.Parent:findFirstChild("Left Arm").CanCollide = true part.Parent:findFirstChild("Right Arm").CanCollide = true part.Parent:findFirstChild("Left Leg").CanCollide = true part.Parent:findFirstChild("Right Leg").CanCollide = true end script.Parent.Touched:connect(onTouch)
It would be a complicated script (not for me)..
You'd have to add a StringValue called "CurrentOwner" also what in the world are you doing setting a player's .Cancollide to true when they're set to true by default? also finding humanoid is really important, just like finding the true player, to later make sure the player has owned one spawn so he doesn't own TWO spawns..
--This is to make sure the player already owned a spawn or not. --Put me in Workspace or ServerScript Game:GetService("Players").PlayerAdded:connect(function(plr) local Owned=Instance.new("BoolValue",plr) Owned.Value=false end)
local p=script.Parent local Owner=script.Parent:WaitForChild("CurrentOwner") Owner.Value="None" --Spawn starts with no owner p.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") and Game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) then local human=hit.Parent:FindFirstChild("Humanoid") local player=Game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) local Owned=player:WaitForChild("OwnedSpawn") --Making sure player hasn't owned another spawn, this value will be created in another script, in Workspace or ServerScriptService. if Owner.Value=="None" and Owned.Value==false then Owned.Value=true Owner.Value=player.Name end end end) --Player Character function, for spawning. Game:GetService("Players").PlayerAdded:connect(function(plr) plr.CharacterAdded:connect(function(c) local t=c:WaitForChild("Torso") if Owned.Value:lower()==plr.Name:lower() then t.CFrame=CFrame.new(p.CFrame.p)*CFrame.new(0,3.5,0) --"Spawn" end end) end) --Player left, reset owner value to None Game:GetService("Players").PlayerRemoving:connect(function(plr) if plr.Name:lower()==Owner.Value:lower() then Owner.Value="None" end end)
Haven't tested it.