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

Scripting help Making a Spawn like miner's haven!?! (READ)

Asked by
Kenley67 -12
7 years ago

I'm working on a game called King Ace, and I made spawns but I want people to spawn in them randomly only 4 people and I don't know how I've tried everything I know and if someone owns that spawn no one else can go there unless that person leaves could someone help with this script?

0
Post what you've tried. If you actualy tried everything you'd have had a solution RubenKan 3615 — 7y

2 answers

Log in to vote
1
Answered by 7 years ago

This is just a choice

What if you put a value in the spawner called taken a BoolValue and then based it off if someone is touching then that value is set to true else it means false and people can spawn there but dont use a actual spawn

1
That makes no sense honestly I want it so as soon as they join it looks for a open thing and it automatically teleports them there Kenley67 -12 — 7y
1
Yes you would do a onplayer added here johndeer2233 439 — 7y
Ad
Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

To check if the spawns are taken, you can insert a BoolValue called "Taken". Now group all the spawns together in Workspace and sort through each of them using the for loop to check if they are taken and out of the non-taken spawns, spawn the players at a random one. Here is an example of what I am talking about:

--(Server script)

local availableSpawns = {}

for i,v in pairs(game.Workspace.Spawns:GetChildren()) do
    table.insert(availableSpawns, v)
end
for i,v in pairs(game.Workspace.Spawns:GetChildren()) do
    v.Taken.Changed:connect(function()
        if v.Taken.Value == true then
            table.remove(availableSpawns, v)
        else
            table.insert(availableSpawns, v)
        end
    end)
end

game.Players.PlayerAdded:connect(function(plr)
    repeat wait() until plr and plr.Character
    local spawn = availableSpawns[math.random(1, #availableSpawns)]
    plr.Character.Torso.CFrame = CFrame.new(spawn.Position)
    spawn.Taken.Value = true
end

I can't make it where when the player leaves, his spawn's "Taken" value will turn to False because I do not know how you want (or will) have the game set up. Hopefully you can figure out the rest!

0
thehybrid576 I added you I'm Gonna invite you to team create in a minute Kenley67 -12 — 7y
0
thehybrid you literally took what I said a gave him this johndeer2233 439 — 7y
0
I never read yours so don't complain, also Kenley ok, message me on roblox when you are ready, my username is "uwot_m9" thehybrid576 294 — 7y

Answer this question