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

Trying make it where if they has >= 5 rebirths for leaderstats than the door CanCollide is false?

Asked by 5 years ago

I tried it as local script and regular still not working.

local plr = game.Players.LocalPlayer
leaderstats = plr:WaitForChild("leaderstats")
Rebirths = leaderstats:FindFirstChild("Rebirths")

if plr.Rebirths.Vaule >= 5 then
    game.Workspace.RedCourtRebirth5.CanCollide = false
    game.Workspace.FiveRebirth.Rebirth5Door.CanCollide = false
elseif 
    plr.Leaderstats.Rebirths.Value < 5 then
    game.Workspace.RedCourtRebirth5.CanCollide = true
    game.Workspace.FiveRebirth.Rebirth5Door.CanCollide = true
end

2 answers

Log in to vote
0
Answered by 5 years ago

This is because your if statements only run once, and that's instant. You'll need a changed event to check this.

local plr = game:GetService("Players").LocalPlayer
local leaderstats = plr:WaitForChild("leaderstats")
local Rebirths = leaderstats:FindFirstChild("Rebirths")
Rebirths.Changed:Connect(function(newValue)
    if newValue >= 5 then
        game.Workspace.RedCourtRebirth5.CanCollide = false
        game.Workspace.FiveRebirth.Rebirth5Door.CanCollide = false
    elseif plr.Leaderstats.Rebirths.Value < 5 then
        game.Workspace.RedCourtRebirth5.CanCollide = true
        game.Workspace.FiveRebirth.Rebirth5Door.CanCollide = true
    end
end)

You also shouldn't be checking those types of requirements on the client, as the client can manipulate the requirements to a minimum.

Ad
Log in to vote
0
Answered by
SCP774 191
5 years ago

You forgot to use a function and listener for this. Codes without a function/listener will only run once when the server started up. Therefore, it will cache the player's rebirth stat.

There are 3 types of functions. This is the most common one. (Unrecommended)

function whateverYouWant(argument)
    if argument == "hi" then
        print("Hello!")
    end
end

Why is it not good? It's because that code will take more memory for the server to run it. If you are making a large game, it'll causes lag.

The second one is commonly used because you don't have to open a new line for your listener. (Still unrecommended)

game.Workspace.Dummy.Humanoid.Died:Connect(function(argument)
    warn("Oh no! Dummy down! D:")
end)

This one has the same issue that the upper one has.

The third one is the best.

local function whateverYouWant(argument)
    if argument == "hi" then
        print("Hello!")
    end
end

If you only use the function code without listeners, they will never run.

Functions are like variables, you can store them into a variable. (Or remote function/remote event inside a script)

local function checkPassword(pass)
    if pass == "password" then
        return true
    end
end

local passed = checkPassword(password)
if passed == true then
    print("yay!")
end

I hope these helped you! For more information about functions/listeners, I recommend you to go on Roblox's API reference website or just learn it yourself! Good luck developing!

0
Thanks! NeriodKid 6 — 5y
0
The Died event passes no parameters, do not give OP code that will error. User#19524 175 — 5y

Answer this question