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

Is the a way to prevent player from resetting to get skips back?

Asked by 5 years ago

Working on a skip stage for my obby. Let's say player A has used his 3 skips, but when he dies, he gets the 3 skips back without waiting 2 minutes to get new skip. I'm using a local script.

local player = game.Players.LocalPlayer
local stage = player:WaitForChild("leaderstats"):FindFirstChild("Stage")
local skipped = player:WaitForChild("leaderstats"):FindFirstChild("StageSkipped")
local skipLimit = player:WaitForChild("Skip")
local originalLimit = 3

script.Parent.Text = "Skip Stage: ("..originalLimit + skipLimit.Value..")" 

script.Parent.MouseButton1Click:Connect(function()
    if originalLimit ~= 0 then
        originalLimit = originalLimit - 1
        stage.Value = stage.Value + 1
        skipped.Value = skipped.Value + 1
        script.Parent.Text = "Skip Stage: ("..originalLimit + skipLimit.Value..") "
        if player ~= nil and player.Character ~= nil and player.Character:FindFirstChild("Humanoid").Health > 0 then
            player.Character.HumanoidRootPart.CFrame = game.Workspace.CheckPoints:FindFirstChild(stage.Value).CFrame + Vector3.new(0,3,0)
        end
    elseif originalLimit == 0 and skipLimit.Value ~= 0 then
        skipLimit.Value = skipLimit.Value - 1
        stage.Value = stage.Value + 1
        skipped.Value = skipped.Value + 1
        script.Parent.Text = "Skip Stage: ("..originalLimit + skipLimit.Value..") "
        if player ~= nil and player.Character ~= nil and player.Character:FindFirstChild("Humanoid").Health > 0 then
            player.Character.HumanoidRootPart.CFrame = game.Workspace.CheckPoints:FindFirstChild(stage.Value).CFrame + Vector3.new(0,3,0)
        end
    end
end)

while wait(120) do --120 means 2 minutes
    if originalLimit < 3 then --if the originalLimit variable is less then 3 it will add 1 to it every 2 minutes
        originalLimit = originalLimit + 1
        script.Parent.Text = "Skip Stage: ("..originalLimit + skipLimit.Value..") "
    end
end

Any help or suggestions would be great! Thanks!

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

First of all there should be a respawn timer before the player skips back and add a humanoid then add a CharacterAutoLoads and turn it false after 2 minutes it turns the CharacterAutoLoads to true and anyways time for the fix

local player = game.Players.LocalPlayer
local stage = player:WaitForChild("leaderstats"):FindFirstChild("Stage")
local skipped = player:WaitForChild("leaderstats"):FindFirstChild("StageSkipped")
local skipLimit = player:WaitForChild("Skip")
local originalLimit = 3
local hum = player.Character:WaitForChild("Humanoid")
script.Parent.Text = "Skip Stage: ("..originalLimit + skipLimit.Value..")" 

script.Parent.MouseButton1Click:Connect(function()
    if originalLimit ~= 0 then
        originalLimit = originalLimit - 1
        stage.Value = stage.Value + 1
        skipped.Value = skipped.Value + 1
        script.Parent.Text = "Skip Stage: ("..originalLimit + skipLimit.Value..") "
        if player ~= nil and player.Character ~= nil and player.Character:FindFirstChild("Humanoid").Health > 0 then
            player.Character.HumanoidRootPart.CFrame = game.Workspace.CheckPoints:FindFirstChild(stage.Value).CFrame + Vector3.new(0,3,0)
        end
    elseif originalLimit == 0 and skipLimit.Value ~= 0 then
        skipLimit.Value = skipLimit.Value - 1
        stage.Value = stage.Value + 1
        skipped.Value = skipped.Value + 1
        script.Parent.Text = "Skip Stage: ("..originalLimit + skipLimit.Value..") "
        if player ~= nil and player.Character ~= nil and player.Character:FindFirstChild("Humanoid").Health > 0 then
            player.Character.HumanoidRootPart.CFrame = game.Workspace.CheckPoints:FindFirstChild(stage.Value).CFrame + Vector3.new(0,3,0)
        end
    end
end)

hum.Died:connect(function()
 player.Parent.CharacterAutoLoads = false
 wait(120) 
     if originalLimit < 3 then --if the originalLimit variable is less then 3 it will add 1 to it every 2 minutes
         originalLimit = originalLimit + 1
         script.Parent.Text = "Skip Stage: ("..originalLimit + skipLimit.Value..") "
      player.Parent.CharacterAutoLoads = true
    end
end)
0
hum:Died is not a valid member of humanoid? wot XviperIink 428 — 5y
0
oh wait Animescapetower 10 — 5y
0
ok there Animescapetower 10 — 5y
0
and yeah the : is pretty much causes the error and i fixed it using the .died:connect(function() because it is a event Animescapetower 10 — 5y
View all comments (6 more)
0
tried that... doesnt work lmao XviperIink 428 — 5y
0
ok so what is the problem Animescapetower 10 — 5y
0
1 there is no problem, and yeah you may have to wait and yeah i tested this ingame due to studio being non-responsive when i test Animescapetower 10 — 5y
0
and yeah don't forget to reset Animescapetower 10 — 5y
0
nvm now it did type wrongly.. my bad XviperIink 428 — 5y
0
i am just gonna continue with making a sphere generator from a event Animescapetower 10 — 5y
Ad

Answer this question