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

IntValue inside of game.ReplicatedStorage isn't changing??

Asked by
DemGame 271 Moderation Voter
4 years ago
Edited 4 years ago

I have a script inside of a model in workspace that changes an intValue to indicate how many seconds are left inside of one round located in ReplicatedStorage every time a second passes. When I test the game and touch the part that starts a round, the value doesn't change at all. Any suggestions?

01function onTouched(part)
02    local h = part.Parent:findFirstChild("Humanoid")
03    local timeRemaining = 0
04    local seconds = game.ReplicatedStorage.Seconds.Value
05    seconds = 0
06    if h~=nil then
07        script.Parent.Position = Vector3.new(-12.15, 621.894, 47.98)
08        script.Parent.Parent:FindFirstChild("Start").SurfaceGui.SIGN.Text = "3"
09        wait(1)
10        script.Parent.Parent:FindFirstChild("Start").SurfaceGui.SIGN.Text = "2"
11        wait(1)
12        script.Parent.Parent:FindFirstChild("Start").SurfaceGui.SIGN.Text = "1"
13        wait(1)
14        script.Parent.Parent:FindFirstChild("Start").SurfaceGui.SIGN.Text = "GO!"
15        wait(0.5)
View all 35 lines...

P.S. I'm new to scripting forums, so I may have formatted a things wrong. Sorry about that.

0
are you in a local script? hhhhhhhhhhhjjhh 12 — 4y

1 answer

Log in to vote
0
Answered by
gskw 1046 Moderation Voter
4 years ago

First, the code reads the value of the IntValue:

1local seconds = game.ReplicatedStorage.Seconds.Value

Now a copy of the value is stored in this local variable.

The code then goes on to update that variable, while leaving the IntValue object itself intact:

1seconds = 0
2-- snip
3seconds = seconds - 1

The issue is that seconds doesn't actually point to the IntValue in ReplicatedStorage; it is simply a copy of the IntValue's original Value. When the code assigns to seconds, it's kind of like imagining that the IntValue is changed - it doesn't have any effect on the IntValue itself. What you want instead is this:

1local seconds = game.ReplicatedStorage.Seconds -- Grab reference to IntValue object
2seconds.Value = 0 -- modify the IntValue object
3-- snip
4seconds.Value = seconds.Value - 1
5-- Alternatively, this is now possible on Roblox:
6-- seconds.Value -= 1
1
Thank you! It worked. DemGame 271 — 4y
0
No problem! Make sure to mark the answer as accepted if your question is resolved! :) gskw 1046 — 4y
Ad

Answer this question