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

Help.. One Player Spawn script?

Asked by
RAYAN1565 691 Moderation Voter
9 years ago

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) 

1 answer

Log in to vote
1
Answered by
Nymint 85
9 years ago

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.

1
I tested my game with my friend. Once you join the game, we both go to different spawns and do not spawn together on the same one. But once you reset your character or die, thats when we go to each others spawn. RAYAN1565 691 — 9y
0
Because it does that once a player touches the spawn. Do not use spawnlocations, dude. just use some normal bricks. Nymint 85 — 9y
2
Fixed it. The Neutral property in the spawns was set to true. I just set them to false. RAYAN1565 691 — 9y
Ad

Answer this question