How to use .Changed?

I had a while loop but changed it to .Changed because I was told that it was better in this scenario.

I have never used .Changed and don’t know how to use it. Can someone please explain?

local Remote = game:GetService("ReplicatedStorage").ColorChanging

Remote.Changed:Connect(function()
	
	local RColor = script.Parent.RedBar.SliderValue.Text
	local GColor = script.Parent.GreenBar.SliderValue.Text
	local BColor = script.Parent.BlueBar.SliderValue.Text

	Remote:FireServer(RColor, GColor, BColor)
	
end)

That is what I have written down, but it doesn’t work.

4 Likes

the changed function detects if a property has been changed, it doesn’t detect functions getting called

1 Like

Changed fires when a property of an instance, well changes. If you are trying to detect server events then use OnClientEvent instead.

Yes I tried Remote.OnClientEvent:Connect(function() Already but I got nothing.

1 Like

This is a local script right? Put a print statement inside of the onclient event and check if it prints or not.

1 Like

what is this script trying to achieve?

It will make it so that the text on a textlable is equal to either an R,G, or B value

The functions in the video no longer work as well.

2 Likes

ooh, you want to detect when the RGB value changes, so in your click detection script, send a request to the server there after it’s done moving.

1 Like

.Changed fires when a property of the object it’s connected to is changed.
In this case, I assume you’re trying to consistently fire a RemoteEvent. .Changed basically has nothing to do with this (in regards to the RemoteEvent instance itself), although the person that told you to use .Changed is correct, in most scenarios.
Generally, firing RemoteEvents in a while loop is a pretty bad idea. What I recommend doing is checking if those bars change at all, and then firing the event then.

1 Like

hes right, but instead, try to use GetPropertyChangedSignal for position

documentation:

1 Like

Well he already has a script that detects when the mouse is clicked and moves the bar, so just fire the remote there

That is another thing I havent really tampered with but after reading I think I kind of get it.

It looked pretty straight forawrd but I get this error:

Argument 1 missing or nil

local Remote = game:GetService("ReplicatedStorage").ColorChanging

Remote:GetPropertyChangedSignal():Connect(function()
	
	local RColor = script.Parent.RedBar.SliderValue.Text
	local GColor = script.Parent.GreenBar.SliderValue.Text
	local BColor = script.Parent.BlueBar.SliderValue.Text

	Remote:FireServer(RColor, GColor, BColor)
	
end)

in the getpropertychangedsignal, put the string of the property you want to detect, maybe position for this case?

right now you’re waiting for the remote to be changed instead of waiting for .OnClientEvent (server doing Remote:FireClient(player, data) or Remote:FireAllClients(data)). meaning doing Remote.Changed is just pointless

you should use .Changed on your slidervalues instead and fire the remote when they’re being changed

also :GetPropertyChangedSignal() requires a property name so you can detect a change in a specific argument. you didn’t specify a property so you got an error

SliderValue:GetPropertyChangedSignal("Text"):Connect(function(newVal)
    
end)

Alright you have the wrong idea on how to use remote events. You want to do the property changed signal on the sliders, not the remote event. Remote events are used to send and/or receive data from the server.

2 Likes

Exactly what I said earlier lol

2 Likes

since you probably want to :FireServer(colors) everytime a value changes
i’m sure the first thing you’re thinking is to do something like this

local Holder = script.Parent -- avoid using script.Parent so many times (just make a variable)
local RColor = Holder.RedBar.SliderValue
local GColor = Holder.GreenBar.SliderValue
local BColor = Holder.BlueBar.SliderValue

RColor:GetPropertyChangedSignal("Text"):Connect(function(newVal)
    Remote:FireServer(RColor.Text, GColor.Text, BColor.Text)
end)

GColor:GetPropertyChangedSignal("Text"):Connect(function(newVal)
    Remote:FireServer(RColor.Text, GColor.Text, BColor.Text)
end)

BColor:GetPropertyChangedSignal("Text"):Connect(function(newVal)
    Remote:FireServer(RColor.Text, GColor.Text, BColor.Text)
end)

but you can shorten it with a loop

local Holder = script.Parent
local RColor = Holder.RedBar.SliderValue
local GColor = Holder.GreenBar.SliderValue
local BColor = Holder.BlueBar.SliderValue

for _, Color in ipairs(Holder:GetChildren()) do
   -- check if there's a SliderValue incase you try to access another element
    if not Color:FindFirstChild("SliderValue") then continue end
    Color.SliderValue:GetPropertyChangedSignal("Text"):Connect(function()
        Remote:FireServer(RColor.Text, GColor.Text, BColor.Text)
    end)
end

wrong reply

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.