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

How to make sure two variables are the same if one changes?

Asked by 2 years ago
Edited 2 years ago
script.Parent.Value:GetPropertyChangedSignal("Value"):Connect(function()
    script.Parent.Text = script.Parent.Value.Value
end)

error: text still isnt changing?

this is the script inside the text label that will change the text based on the IntValue's Value, but the text is not changing from 0 to 9292, because the IntValue is 9292 but text is not. How do I connect these two variables?

btw this is the script that changes the value, which is perfectly fine.

local ts = game:GetService("TweenService")
local player = game.Players.LocalPlayer
local p1 = script.Parent.Parent.rollmove.RI
local p2 = script.Parent.Parent.rollmove.RII
local box = script.Parent.Parent.rollmove.Box
local click = script.Parent.ClickDetector
local dicee = script.Parent.Parent.rollmove.dice:GetChildren()
local dice = script.Parent.Parent.rollmove.dice
local dicenum = #dicee

for i = 1,dicenum do
    local diceget = dicee[i]
    diceget.Anchored = true
end

local function roll()
    script.Parent.SurfaceGui.Rolling.Visible = true
    script.Parent.SurfaceGui.Roll.Visible = false
    player:WaitForChild("PlayerGui").ScoreCard.Background.line1.Rolls.I.Value.Value = player:WaitForChild("PlayerGui").ScoreCard.Background.line1.Rolls.I.Value.Value + 1
    player:WaitForChild("PlayerGui").ScoreCard.Background.line1.Rolls.II.Value.Value = player:WaitForChild("PlayerGui").ScoreCard.Background.line1.Rolls.II.Value.Value + 1
    player:WaitForChild("PlayerGui").ScoreCard.Background.line1.Rolls.III.Value.Value = player:WaitForChild("PlayerGui").ScoreCard.Background.line1.Rolls.III.Value.Value + 1
    player:WaitForChild("PlayerGui").ScoreCard.Background.line1.Rolls.IV.Value.Value = player:WaitForChild("PlayerGui").ScoreCard.Background.line1.Rolls.IV.Value.Value + 1
    player:WaitForChild("PlayerGui").ScoreCard.Background.line1.Rolls.V.Value.Value = player:WaitForChild("PlayerGui").ScoreCard.Background.line1.Rolls.V.Value.Value + 1
    wait()
    local function moveItem(item, wp)
        local ti = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
        local tween = ts:Create(item, ti, { Position = wp.Position})
            tween:Play()
        wait(2)
    end
    local function moveItems(item, wp)
        local ti = TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
        local tween = ts:Create(item, ti, { Position = wp.Position})
        tween:Play()
        wait(0.1)
    end
    for i = 1,dicenum do
        local diceget = dicee[i]
        moveItems(diceget, p1)
    end
    moveItem(box, p1)
    for i = 1,dicenum do
        local diceget = dicee[i]
        diceget.Transparency = 1
        moveItems(diceget, p2)
    end
    moveItem(box, p2)
    box.Orientation = Vector3.new(0,180,180)
    for i = 1,dicenum do
        local diceget = dicee[i]
        diceget.Transparency = 0
        diceget.Anchored = false
    end
    wait(2)
    for i = 1,dicenum do
        local diceget = dicee[i]
        diceget.Anchored = true
        diceget.Transparency = 1
        moveItems(diceget, p1)
    end
    moveItem(box,p1)
    box.Orientation = Vector3.new(0,0,0)
    script.Parent.SurfaceGui.Rolling.Visible = false
    script.Parent.SurfaceGui.Roll.Visible = true
end

click.MouseClick:Connect(roll)
0
you can use the function :GetPropertyChangedSignal to accomplish this JesseSong 3916 — 2y
0
i dont think i used it right, how do i use it right? Jakob_Cashy 79 — 2y
0
you need to connect the function that's why it errored. use script.Parent.Value:GetPropertyChangedSignal("Value"):Connect(function() JesseSong 3916 — 2y
0
Define the local player first, then replace game.StarterGui to: player:WaitForChild("PlayerGui") JesseSong 3916 — 2y
View all comments (6 more)
0
oh Jakob_Cashy 79 — 2y
0
make sure it's in startergui or starterplayerscipts (also make sure it's a localscript) JesseSong 3916 — 2y
0
the second script is inside a part with a click detector that changes the values and moves some things, the first script is inside a text label that is getting its text changed Jakob_Cashy 79 — 2y
0
if that's the case then remove line 2. add a player event JesseSong 3916 — 2y
0
ima re-edit the comment later JesseSong 3916 — 2y
0
uhhh whats a player event? also which script Jakob_Cashy 79 — 2y

2 answers

Log in to vote
1
Answered by
JesseSong 3916 Moderation Voter Community Moderator
2 years ago
Edited 2 years ago

(Problem: Re-edited)

The problem is that you're using a local script inside of a server script which will result in an error. Instead, use a server script.

Add a remote in replicatedstorage

Server Script


local ts = game:GetService("TweenService") local p1 = script.Parent.Parent.rollmove.RI local p2 = script.Parent.Parent.rollmove.RII local box = script.Parent.Parent.rollmove.Box local click = script.Parent.ClickDetector local dicee = script.Parent.Parent.rollmove.dice:GetChildren() local dice = script.Parent.Parent.rollmove.dice local dicenum = #dicee for i = 1,dicenum do local diceget = dicee[i] diceget.Anchored = true end script.Parent.ClickDetector.MouseClick:Connect(function(player) script.Parent.SurfaceGui.Rolling.Visible = true script.Parent.SurfaceGui.Roll.Visible = false wait() local function moveItem(item, wp) local ti = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0) local tween = ts:Create(item, ti, { Position = wp.Position}) tween:Play() wait(2) end local function moveItems(item, wp) local ti = TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0) local tween = ts:Create(item, ti, { Position = wp.Position}) tween:Play() wait(0.1) end for i = 1,dicenum do local diceget = dicee[i] moveItems(diceget, p1) end moveItem(box, p1) for i = 1,dicenum do local diceget = dicee[i] diceget.Transparency = 1 moveItems(diceget, p2) end moveItem(box, p2) box.Orientation = Vector3.new(0,180,180) for i = 1,dicenum do local diceget = dicee[i] diceget.Transparency = 0 diceget.Anchored = false end wait(2) for i = 1,dicenum do local diceget = dicee[i] diceget.Anchored = true diceget.Transparency = 1 moveItems(diceget, p1) end moveItem(box,p1) box.Orientation = Vector3.new(0,0,0) script.Parent.SurfaceGui.Rolling.Visible = false script.Parent.SurfaceGui.Roll.Visible = true end)

Client

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
player:WaitForChild("PlayerGui").ScoreCard.Background.line1.Rolls.I.Value.Value = player:WaitForChild("PlayerGui").ScoreCard.Background.line1.Rolls.I.Value.Value + 1
player:WaitForChild("PlayerGui").ScoreCard.Background.line1.Rolls.II.Value.Value = player:WaitForChild("PlayerGui").ScoreCard.Background.line1.Rolls.II.Value.Value + 1
player:WaitForChild("PlayerGui").ScoreCard.Background.line1.Rolls.III.Value.Value = player:WaitForChild("PlayerGui").ScoreCard.Background.line1.Rolls.III.Value.Value + 1
player:WaitForChild("PlayerGui").ScoreCard.Background.line1.Rolls.IV.Value.Value = player:WaitForChild("PlayerGui").ScoreCard.Background.line1.Rolls.IV.Value.Value + 1
player:WaitForChild("PlayerGui").ScoreCard.Background.line1.Rolls.V.Value.Value = player:WaitForChild("PlayerGui").ScoreCard.Background.line1.Rolls.V.Value.Value + 1
RemoteEvent:FireServer()

If it doesn't work, let me know so I can fix it.

Going to re-edit this answer soon.

0
You will need to use a remote event to get the playergui JesseSong 3916 — 2y
0
it was a server script tho Jakob_Cashy 79 — 2y
0
Ik, you didn't tell me before that it was in a server script JesseSong 3916 — 2y
0
aight Jakob_Cashy 79 — 2y
View all comments (6 more)
0
try it now, tell me whether it works or not. any more comments will be replied to at 12PM GMT JesseSong 3916 — 2y
0
whats the client Jakob_Cashy 79 — 2y
0
its basically your computer. a client script is another word for local script JesseSong 3916 — 2y
0
do i put local script in the same parent as the regular script? Jakob_Cashy 79 — 2y
0
no. it will error. also make sure to add a remoteevent in replicatedstorage JesseSong 3916 — 2y
0
even tho u didnt answer it, the guy who did didnt put an answer up here so ill give u the points Jakob_Cashy 79 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

When answering, if your answer does not fully solve the question, it should be written as a comment to the question instead of as an answer.
script.Parent.Value:Changed:Connect(function()
script.Parent.Text = script.Parent.Value.Value
end)

This should work

0
it did not Jakob_Cashy 79 — 2y
0
btw it should be .Changed not :Changed JesseSong 3916 — 2y

Answer this question