function onTouched(part) name = script.Parent.Name local h = part.Parent:FindFirstChild("Humanoid") if h ~= nil then char = h.Parent player = char:GetPlayerFromCharacter(char) if player ~= nil then leaderstats = player.FindFirstChild("leaderstats") if leaderstats ~= nil then stage = leaderstats:FindFirstChild("Stage") if stage ~= nil then stage.Value = name end end end end end end script.Parent.Touched:connect(onTouched) -- Links event to function
function onTouched(part) name = script.Parent.Name local h = part.Parent:FindFirstChild("Humanoid") if h ~= nil then char = h.Parent player = game:GetService("Players"):FindFirstChild(char.Name) if player ~= nil then leaderstats = player.FindFirstChild("leaderstats") if leaderstats ~= nil then stage = leaderstats:FindFirstChild("Stage") if stage ~= nil then stage.Value = name end end end end end -- Whatever will be touched has to be here SpawnLocation = script.Parent -- Make sure it's the right object SpawnLocation.Touched:Connect(onTouched)
You put an extra end and you're trying to call a function that isn't there on line 6
function onTouched(part) name = script.Parent.Name local h = part.Parent:FindFirstChild("Humanoid") if h ~= nil then char = h.Parent player = char:GetPlayerFromCharacter(char) -- HERE <<<<<<<<<<<<<<<<<<<<< if player ~= nil then leaderstats = player.FindFirstChild("leaderstats") if leaderstats ~= nil then stage = leaderstats:FindFirstChild("Stage") if stage ~= nil then stage.Value = name end end end end end end -- HERE <<<<<<<<<<<<<<<<<<<<< script.Parent.Touched:connect(onTouched) -- Links event to function
you can fix this by changing the code like so:
function onTouched(part) name = script.Parent.Name local h = part.Parent:FindFirstChild("Humanoid") if h ~= nil then char = h.Parent player = game:GetService("Players"):FindFirstChild(char.Name) if player ~= nil then leaderstats = player.FindFirstChild("leaderstats") if leaderstats ~= nil then stage = leaderstats:FindFirstChild("Stage") if stage ~= nil then stage.Value = name end end end end end
p.s. put the script into the checkpoint and make sure to name the part the stage number
local plrs = game:GetService"Players" function onTouch(part) local plr = plrs:GetPlayerFromCharacter(part.Parent) if plr then --You don’t need the ~= nil part, it’s redundant and does nothing local leaderstats = plr.leaderstats local stage = leaderstats.Stage stage.Value = script.Parent.Name end end script.Parent.Touched:Connect(onTouch) --Connect not connect
On a side note, switch to Connect
, as ROBLOX may remove connect
soon.