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

I need to share a variable and put the value onto a different script inside a TextLabel Help?

Asked by 4 years ago

I have a score variable holding a value of 0, I want the value to be printed onto a script inside a TextLabel in StarterGui.

Score = 0

local clickdetector = script.Parent:WaitForChild("ClickDetector")


math.random(tick())

clickdetector.MouseClick:Connect(function()

    script.Parent.Position = Vector3.new(math.random(20, 70),math.random(10, 20),math.random(20, 70))
    Score = Score + 1
    print(Score)



end)

local ScreenGui = script:FindFirstAncestorWhichIsA("ScreenGui")
local TextLabel = ScreenGui:FindFirstChildWhichIsA("TextLabel")

TextLabel.Text = 

1 answer

Log in to vote
0
Answered by
Raccoonyz 1092 Donator Moderation Voter
4 years ago
Edited 4 years ago

Use number values (https://developer.roblox.com/en-us/api-reference/class/NumberValue). Here's an example.

Score = 0

local clickdetector = script.Parent:WaitForChild("ClickDetector")
local NumberValue = Instance.new("NumberValue")
NumberValue.Name = "Number"
NumberValue.Parent = game.ReplicatedStorage


math.random(tick())

clickdetector.MouseClick:Connect(function()

    script.Parent.Position = Vector3.new(math.random(20, 70),math.random(10, 20),math.random(20, 70))
    Score = Score + 1
    local NumberValue = Instance.new("NumberValue")
    NumberValue.Value = Score


end)
local ScreenGui = script:FindFirstAncestorWhichIsA("ScreenGui")
local TextLabel = ScreenGui:FindFirstChildWhichIsA("TextLabel")
local NV = game.ReplicatedStorage:FindFirstChild("Number")
TextLabel.Text = NV.Value
Ad

Answer this question