The codes that I am using are for spawn points and for a rebirth system, the rebirth system and spawn point system both need to create a leaderstats folder for “Stage” which causes problems. When I playtest my game in studio I see in the output that Stage is not a valid member of Folder “(myname).leaderstats” and I am a huge noob to scripting so ive been trying to figure it out for a while i’d assume it’s because im trying to create 2 of the same folder in leaderstats but I don’t know how to make it only do 1 with having both scripts work properly. Since I am a noob, these are not my scripts but I edited them to make them both work for my game and they are just interfering with each other and I’m experimenting.
SPAWNPOINT SCRIPT
-- local checkpoints = workspace:WaitForChild("Checkpoints")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local stage = Instance.new("IntValue")
stage.Name = "Stage"
stage.Value = 0
stage.Parent = leaderstats
player.CharacterAdded:Connect(function(char)
local hum = char:WaitForChild("Humanoid")
wait()
char:MoveTo(checkpoints[stage.Value].Position)
hum.Touched:Connect(function(hit)
if hit.Parent == checkpoints then
if tonumber(hit.Name) == stage.Value + 1 then
stage.Value = stage.Value + 1
end
end
end)
end)
end)
REBIRTH SCRIPTS
-- local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local rebirth_Event = ReplicatedStorage:WaitForChild("rebirthPlayer")
local STAGE_REQUIRED = 75
local function rebirthPlayer(LocalPlayer)
local Stage = LocalPlayer.leaderstats:WaitForChild("Stage")
local Rebirths = LocalPlayer.leaderstats:WaitForChild("Rebirths")
Rebirths.Value += 1
Stage.Value = 0
end
Players.PlayerAdded:Connect(function(LocalPlayer)
local leaderstats = Instance.new("Folder") ; leaderstats.Parent = LocalPlayer
leaderstats.Name = "leaderstats"
local Stage = Instance.new("NumberValue") ; Stage.Parent = leaderstats
Stage.Name = "Stage" ; Stage.Value = 1
local Rebirths = Instance.new("NumberValue") ; Rebirths.Parent = leaderstats
Rebirths.Name = "Rebirths"
if RunService:IsStudio() then
Stage.Value = 75
end
end)
rebirth_Event.OnServerEvent:Connect(function(LocalPlayer)
local Stages = LocalPlayer.leaderstats:WaitForChild("Stage")
if Stages.Value >= STAGE_REQUIRED then
rebirthPlayer(LocalPlayer)
end
end)
-- local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local LocalPlayer = Players.LocalPlayer
local Stage = LocalPlayer.leaderstats:WaitForChild("Stage")
local rebirth_Event = ReplicatedStorage:WaitForChild("rebirthPlayer")
local togBtn = script.Parent.togBtn
local rebirthBtn = script.Parent.Parent.rebirthBtn
local closeBtn = script.Parent.closebtn
local rebirthFrame = script.Parent
local stgReq = rebirthFrame.stgReq
local STAGE_REQUIRED = 75
local SuffixTable = {'','K+','M+','B+','T+','Qd+','Qn+','S+','Sp+','O+','N+','D+','U+','DD+','Td+','Qd+','Qnd+','Sd+','Spd+'
,'Od+','Nd+','Vg+','Ug+','Dg+','Tv+','Qt+','Qv+','Sv+','Sg+','Ov+','Ng+',
'Tg+','Ut+','Dt+','Tt+','Qg+','Qtg+','Sg+','Spt+','Otg+','Nag+','Ung+','Dug+'
,'Teg+','Qag+','Qng+','Sag+','Spa+','Oag+','Nva+','Ct+'}
local function abbNum(Value)
for i=1, #SuffixTable do
if tonumber(Value) < 10^(i*3) then
return math.floor(Value/((10^((i-1)*3))/100))/(100)..SuffixTable[i]
end
end
end
Stage:GetPropertyChangedSignal("Value"):Connect(function()
stgReq.Text = "Stage required: " .. abbNum(STAGE_REQUIRED)
end)
togBtn.MouseButton1Click:Connect(function()
if Stage.Value >= STAGE_REQUIRED then
rebirth_Event:FireServer()
end
end)
local Debounce = false
rebirthBtn.MouseButton1Click:Connect(function()
if Debounce == false then
rebirthFrame.Visible = true
Debounce = true
elseif Debounce == true then
rebirthFrame.Visible = false
Debounce = false
end
end)
closeBtn.MouseButton1Click:Connect(function()
if Debounce == true then
rebirthFrame.Visible = false
Debounce = false
end
end)