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

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

Asked by 2 years ago

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

0
change Bool_Value.Value = true to Bool_Value.Value = not Bool_Value.Value WINDOWS10XPRO 438 — 2y
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. greatneil80 2647 — 2y

2 answers

Log in to vote
0
Answered by 2 years ago

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)
Ad
Log in to vote
0
Answered by 2 years ago

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

Answer this question