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

How can I make a variable accessable from all scripts?

Asked by 4 years ago

So I have a variable called BoughtHouse. BoughtHouse = false right now.

But I need it to be accesable from another script in the workspace as well.

0
Use a module script to store the variable instead SerpentineKing 3885 — 4y

1 answer

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

Use something called a BoolValue.

BoolValues are either true or false, now the script that I'm creating here is if the player does not own the house the player will get damaged.

Instance a boolvalue in the player like this;

game.Players.PlayerAdded:Connect(function(player)
        local leaderstats = Instance.new("Folder")
        leaderstats.Name = "leaderstats"
        leaderstats.Parent = player

        local BoughtHouse = Instance.new("BoolValue", leaderstats)
        BoughtHouse.Name = "BoughtHouse"
    end)

then you can access it from another script

script.Parent.Touched:Connect(function(hit)
        local Humanoid = hit.Parent:FindFirstChild("Humanoid")
        if (Humanoid ~= nil) then
            local Character = hit.Parent

            local Player = game.Players:GetPlayerFromCharacter(Character)

            if Player.leaderstats.BoughtHouse == false then
                Humanoid:TakeDamage(20)
            end
        end
    end)

or you can use modulescripts.

Ad

Answer this question