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

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

Asked by 5 years ago
Edited 5 years ago

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:

1script.Parent.MouseButton1Click:Connect(function()
2 
3game.ReplicatedStorage.LevelEvent:FireServer()
4 
5end)

Script:

1   --function
2 
3game.ReplicatedStorage.LevelEvent.OnServerEvent:Connect(function()
4 
5script.Parent.Parent.Text = game.ReplicatedStorage.Level.Value
6 
7wait(1)
8 
9end)

1 answer

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

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

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

Local Script 2

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

For more on BindableEvents, click me.

0
thanks, although I had to adjust due to the fact that there was an infinite yield on "BindableEvent" jesusbeef 33 — 5y
Ad

Answer this question