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

What to do So if I touch previous checkpoint again leaderstat should change to previous num. again? [closed]

Asked by 3 years ago

These are the scripts. :- Inside every checkpoint

-- inside the each and every checkpoint
local spawn = script.Parent
spawn.Touched:connect(function(hit)
    if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        local checkpointData = game.ServerStorage:FindFirstChild("CheckpointData")
        if not checkpointData then
            checkpointData = Instance.new("Model", game.ServerStorage)
            checkpointData.Name = "CheckpointData"
        end

        local checkpoint = checkpointData:FindFirstChild(tostring(player.userId))
        if not checkpoint then
            checkpoint = Instance.new("ObjectValue", checkpointData)
            checkpoint.Name = tostring(player.userId)

            player.CharacterAdded:connect(function(character)
                wait()
                character:WaitForChild("HumanoidRootPart").CFrame = game.ServerStorage.CheckpointData[tostring(player.userId)].Value.CFrame + Vector3.new(0, 4, 0)
            end)
        end

        checkpoint.Value = spawn
    end
end)

Another script inside the checkpoint

-- inside the each and every checkpoint
function ot(hit)
if hit.Parent ~= nil then
local player = game.Players:playerFromCharacter(hit.Parent)
if player ~= nil then
if player.leaderstats.Stage.Value == script.Parent.Name - 1 then
local h = hit.Parent:FindFirstChild("Humanoid")
if h ~= nil then
if h.Health ~= 0 then
player.leaderstats.Stage.Value = script.Parent.Name
end end end end end end

script.Parent.Touched:connect(ot)

And this script in Workspace

-- inside the Workspace
function oa(object)
local player = game.Players:playerFromCharacter(object)
if player ~= nil then
local ls = player.leaderstats
local sl = game.Workspace:FindFirstChild(ls.Stage.Value)
print("gah")
object.Torso.CFrame = object.Torso.CFrame + Vector3.new(0,3,0)
wait()
object.Torso.CFrame = sl.CFrame + Vector3.new(0,3,0)
end end

function oe(object)
if object.className == "Player" then
local ack = Instance.new("IntValue")
ack.Name = "leaderstats"
local ack2 = Instance.new("IntValue")
ack2.Name = "Stage"
ack2.Value = 0
ack2.Parent = ack
ack.Parent = object
end end

game.Players.ChildAdded:connect(oe)
game.Workspace.ChildAdded:connect(oa)

What should I add or change in these scripts to make them work like I want to?

0
please elaborate and rephrase, i dont understand A_Mp5 222 — 3y

Closed as Non-Descriptive by JesseSong

This question has been closed because its title or content does not adequately describe the problem you are trying to solve.
Please ensure that your question pertains to your actual problem, rather than your attempted solution. That is, you were trying to solve problem X, and you thought solution Y would work, but instead of asking about X when you ran into trouble, you asked about Y.

Why was this question closed?