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

What do I do? Whenever a player respawns, the value wont keep it to true

Asked by 3 years ago
Edited 3 years ago

When a player resets, the value of "hasPassed" (If a player has passed the simple laser obby) used to be true before they died but now, it just keeps it at false.

How do I keep it at true forever, even if they die?

Script (Type: Normal Script, not local or module, Parent: workspace.Detector):

script.Parent.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)

    if player then
        if hit.Parent:FindFirstChild("Humanoid") then
            local hasPassed = player.Character.SprintScript.HasPassed

            if hasPassed then
                hasPassed.Value = true
            end
        end
    end
end)

Script Explanation:

When a player touched a brick called "Detector", it uses a variable called "player" and it gets the player by getting player from it's character and if the player exists & it has a humanoid then, it also uses a variable called "hasPassed" which is from the player's character and if the boolean value does exist, then the value is true.

2 answers

Log in to vote
0
Answered by 3 years ago

I recommend you to place the value to Player and not to Character. Because everytime Character get Loaded, It will reset everything inside it!

To Put Value inside of the Player, You can use this Script:

Players.PlayerAdded:Connect(function(Player)
    local Folder = Instance.new("Folder",Player)
        Folder.Name = "Put Folder Name Here"

        local Value = Instance.new("BoolValue",Folder)
        Value.Name = "Put Value Name Here"
end)

Hope It Helps!

Ad
Log in to vote
0
Answered by 3 years ago

while loops always do the trick

while true do
      hasPassed.Value = true
      wait(0.00001)
end

Answer this question