#Assign a cave when player joins
1 messages · Page 1 of 1 (latest)
to display their name over the top of the cave you could either use a surface gui or billboard gui but surface gui would be better i think
okay i had a folder with the caves already , what youre explaining now is something that goes under ServerScriptService? im really new so bare with me 😅
** You are now Level 1! **
yes it would be in a script in serverscriptservice
you would do the player added event using the players service
and then iterate through the folder
sorry i might have to do a little more research before i try this
i dont think i know enough to do this yet
thank you anyway though 🥹
thanks ill check him out!
do you want me to give you the code for this now or do you want to figure out how to do it yourself, i personally think the second option is better though
i think seeing how the code actually looks laid out would help me understand it more , so if you can that would be great!
im not gonna copy and paste it in my game ill just use it for reference , id like to make all my scripts myself to get a better understanding of it all
wait let me format it
--[[
Before doing this, in the workspace.Caves folder, make sure that every cave model has a
boolvalue underneath it named Occupied set to false
Also make sure that you create a spawn location for each cave
]]
local Players = game:GetService("Players") -- we are getting the players service
local cavesFolder = workspace.Caves -- we are referencing the caves folder in workspace
Players.PlayerAdded:Connect(function(player) -- this event "PlayerAdded" fires every single time a player joins the game and passes the player
for _, cave : Model in cavesFolder:GetChildren() do -- get children returns all of the children of the caves folder, like cave1, cave2, etc.
local occupied : BoolValue = cave:FindFirstChild("Occupied") -- we then get the occupied boolvalue that is a child of the cave
local spawnLocation = cave:FindFirstChildOfClass("SpawnLocation") -- as well as the spawn location
if not occupied.Value then -- this checks whether or not the cave is occupied, it essentially means, if occupied.Value == false, which means is this cave occupied?
occupied.Value = true -- if it is not occupied, then we make it occupied, by setting the value to true
player.RespawnLocation = spawnLocation -- we set the player's respawn location to the spawn location, so that every time they die, they get teleported to that spawn location
local character = player.Character or player.CharacterAdded:Wait() -- this gets the character model of the player, or prevents the following line of code from running until the character has fully loaded into the game
character:PivotTo(spawnLocation.CFrame + Vector3.new(0, spawnLocation.Size.Y, 0)) -- we move the character model to the position of the spawnLocation + the size of it on the y axis
end
end
end)
all dat in 1 min
9 minutes
** You are now Level 5! **
i think
alr
hopefully the comments make sense idk i tried explaining it the best way i can
i was just about to say the comments are so helpful , thanks a lot for this!
if you get an error you might have skipped a step in the instructions in the beginning
so i should have seperate "SpawnLocation" under all of my cave models? the ones that say Cave1 Cave2 etc?
yea so that the owner of that cave can respawn in that same place
unless you dont want to do that then you can just remove those lines
im sorry but do you think you can explain this line a little for me?
for _, cave : Model in cavesFolder:GetChildren() do
** You are now Level 2! **
everything else is making sense to me now though
its this specific part that i dont really understand
_, cave : Model
whats the underscore doing here?
okay i actually understand the code you made now , you can disregard that last question i asked
_ is a place holder or unused variable
i ended up using your code and just made different comments more suitable for me to remember what everything means , i couldnt figure out how to make this script myself without just doing what you did , assuming there are other ways to do this
but if you did end up using it it would give you the current index in the loop
do you know for loops?
yeah i learned about them a bit when learning python