Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I make a variable accessable from all scripts?

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.

1 comment

0

Use a module script to store the variable instead

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.