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

A script that displays a NumberValue, displays a constant number despite being changed?

So basically, I'm trying to make a script that outputs the result of clicking a TextButton. What this means is that, when I click this button it will fire the remote event which will then transfer to a script.

What this script does is, it displays a Numerical Value. However, when I click this button, the value remains the same number despite it being updated.

LocalScript:

 script.Parent.MouseButton1Click:Connect(function()

game.ReplicatedStorage.LevelEvent:FireServer()

end)

Script:

   --function

game.ReplicatedStorage.LevelEvent.OnServerEvent:Connect(function()

script.Parent.Parent.Text = game.ReplicatedStorage.Level.Value

wait(1)

end)

1 answer

✓ Accepted answer

The server's changes to a GUI's text do not replicate to the PlayerGui. In order to pull this off, you can instead use a BindableEvent with local scripts:

Local Script 1

local event = game:GetService("ReplicatedStorage"):WaitForChild("BindableEvent")
script.Parent.MouseButton1Click:Connect(function()
    event:Fire()
end)

Local Script 2

local event = game:GetService("ReplicatedStorage"):WaitForChild("BindableEvent")
event.Event:Connect(function()
    script.Parent.Parent.Text = tostring(game:GetService("ReplicatedStorage").Level.Value)
    wait(1)
end)

For more on BindableEvents, click me.

1 comment

0

thanks, although I had to adjust due to the fact that there was an infinite yield on "BindableEvent"

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