Hi, what i have set up is if the player joins the game, a intvalue is added and is set to 1. When the player touches the checkpoint, it can’t find it, hence why this script won’t work:
local Checkpoint = script.Parent
local CheckpointNumber = Checkpoint.Name
local function onPartTouched()
local player = game.Players.LocalPlayer
local CurrentCheckpoint = player:FindFirstChild("CurrentCheckpointNumber").Value
if CheckpointNumber == CurrentCheckpoint then
CurrentCheckpoint = CurrentCheckpoint + 1
end
end
Checkpoint.Touched:Connect(onPartTouched())
Oh, I see the problem. You’re trying to get a localplayer out of the player who stepped on the checkpoint. You can’t do that since the script is not in the player. What you should do is use this function: game.Players:GetPlayerFromCharacter(player's character)
Then find the intValue in them. You can get the player’s character by adding a parameter in the onPartTouched() function
local Checkpoint = script.Parent
local CheckpointNumber = Checkpoint.Name
local function onPartTouched(person)
if person.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(person.Parent)
local CurrentCheckpoint = player:FindFirstChild("CurrentCheckpointNumber")
if tonumber(CheckpointNumber) == CurrentCheckpoint then
CurrentCheckpoint.Value = CurrentCheckpoint.Value + 1
end
end
end
Checkpoint.Touched:Connect(onPartTouched())
local part = script.Parent
local num = workspace:FindFirstChild("YOURCHECKPOINTNAME").Name
local db = false
part.Touched:Connect(function(person)
if game.Players:GetPlayerFromCharacter(person.Parent) and not db then
db = true
local plr = game.Players:GetPlayerFromCharacter(person.Parent)
local intvalue = plr:FindFirstChild("YOURINTVALUE")
intvalue.Value = tonumber(num)
wait(1)
db = false
end
end)
Make sure the script inside the checkpoint is a regular script
function setupStats(plr)
local stats = Instance.new(“Folder”)
stats.Name = “leaderstats”
local stage = Instance.new(“NumberValue”)
stage.Name = “Stage”
stage.Value = 1
stats.Parent = plr
stage.Parent = stats
end
function AdvanceStage(plr,checkpoint)
local p = game.Players:GetPlayerFromCharacter(plr)
local stage = p:FindFirstChild(‘leaderstats’):FindFirstChild(‘Stage’)
if p and stage~=nil and plr:FindFirstChild(‘Humanoid’).Health>0 then
if(stage.Value+1) == tonumber(checkpoint) then
stage.Value = stage.Value+1
end
else
return
end
end
game.Players.PlayerAdded:connect(function(p)
setupStats(p)
p.CharacterAdded:connect(function(c)
local curStage = p:FindFirstChild(‘leaderstats’):FindFirstChild(‘Stage’)
if curStage~=nil and checkpointDir:FindFirstChild(tostring(curStage.Value)) then
local point = checkpointDir:FindFirstChild(tostring(curStage.Value))
wait(.3)
c:WaitForChild(‘HumanoidRootPart’).CFrame = CFrame.new(point.Position+Vector3.new(0,5,0))
end
end)
end)
for i,v in pairs(checkpointDir:GetChildren()) do
v.Touched:connect(function(h)
if h.Parent:FindFirstChild(‘Humanoid’) then
AdvanceStage(h.Parent,v.Name)
end
end)
end