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

can server scripts not use a bool value once a local script uses it?

local script runs first

local Bool_Value = script.Parent.is_clicked
script.Parent.MouseButton1Click:Connect(function()
	Bool_Value.Value = true
end)

then the server script

script.Parent.is_clicked.Changed:Connect(function()
	if script.Parent.is_clicked.Value == true then
		print("should have done this")
	end
end)

then it is supposed to say should have done this but i don't even get an error

2 comments

0

change Bool_Value.Value = true to Bool_Value.Value = not Bool_Value.Value

0

baffoon, its not working because client doesnt replicate to server, anything you do on client will show for the client and not the server.

2 answers

try changing this on the server script

script.Parent.is_clicked:GetPropertyChangedSignal("Value"):Connect(t)
	if t == true then
		print("should have done this")
	end
end)

As you are changing the value through a localscript on the client the server never sees the change happen, the value needs to be changed on the server side for the server to know about it. you can fire a remote event from the client to tell the server to change the value but doing that would also make the changed event a bit redundant.

heres an example in your case

local script:

local event = game:GetService("ReplicatedStorage"):WaitForChild("IsClickedChangedEvent")

script.Parent.MouseButton1Click:Connect(function()
	event:FireServer()
end)

server script:

local bool = script.Parent.is_clicked
bool.Changed:Connect(function()
	if bool.Value == true then
		print("should have done this")
	end
end)


local event = Instance.new("RemoteEvent", game:GetService("ReplicatedStorage"))
event.Name = "IsClickedChangedEvent"

event.OnServerEvent:Connect(function(player)
	bool.Value = true
end)

i kept the changed event but you could just put that print in the server event function itself

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