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

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

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)

10 comments

0

you can use the function :GetPropertyChangedSignal to accomplish this

0

i dont think i used it right, how do i use it right?

0

you need to connect the function that's why it errored. use script.Parent.Value:GetPropertyChangedSignal("Value"):Connect(function()

0

Define the local player first, then replace game.StarterGui to: player:WaitForChild("PlayerGui")

0

oh

0

make sure it's in startergui or starterplayerscipts (also make sure it's a localscript)

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

0

if that's the case then remove line 2. add a player event

0

ima re-edit the comment later

0

uhhh whats a player event? also which script

2 answers

✓ Accepted answer

##(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.

10 comments

0

You will need to use a remote event to get the playergui

0

it was a server script tho

0

Ik, you didn't tell me before that it was in a server script

0

aight

0

try it now, tell me whether it works or not. any more comments will be replied to at 12PM GMT

0

whats the client

0

its basically your computer. a client script is another word for local script

0

do i put local script in the same parent as the regular script?

0

no. it will error. also make sure to add a remoteevent in replicatedstorage

0

even tho u didnt answer it, the guy who did didnt put an answer up here so ill give u the points

script.Parent.Value:Changed:Connect(function()
script.Parent.Text = script.Parent.Value.Value
end)

This should work

2 comments

0

it did not

0

btw it should be .Changed not :Changed

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