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

RemotEvent firing but script not detecting it?

Asked by 3 years ago

I have a LocalScript, that, when it is run, will fire a RemoteEvent to a value. But the ServerScript I have written won't detect the RemoteEvent firing and change the value!

Here are the two scripts:

LocalScript

----------Change Value Non-Locally-----------
        local remote = game.ReplicatedStorage.sendData
        local valueToChange = workspace.InvetoryBoxes.Invetory1.InvetoryBox1.Occupied.Value

        valueToChange = true

        remote:FireServer(valueToChange)
        print("Fired!")

ServerScript

local remote = game.ReplicatedStorage.sendData
local valueToChange = workspace.InvetoryBoxes.Invetory1.InvetoryBox1.Occupied.Value
remote.OnServerEvent:Connect(function(valueToChange)
    local value = workspace.CustomizeBoxes.CustBox1.InvetoryBox1.Occupied
    value.Value = true
end)

Any advice?

0
Btw, I didn't include all of the LocalScript because it was just defining and moving the camera. TheB4dComputer 100 — 3y

2 answers

Log in to vote
1
Answered by
KixWater 126
3 years ago
Edited 3 years ago

This might help, first of all, in the local script, do:

local remote = game.ReplicatedStorage:WaitForChild("sendData")

And in the server-side script, when you send over the remote event, the first parameter is the player and the second is what you sent over from the local script. For example,:

remote.OnServerEvent:Connect(function(player, valueToChange)
    local value = workspace.CustomizeBoxes.Cust1.InvetoryBox1.Occupied
    value.Value = true
end)

Hope this helped!

0
You both helped a ton but this guy posted first... TheB4dComputer 100 — 3y
Ad
Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

Okay, so there are several problems. In the local script, you are sending over the value of the boolValue or in other words, the server script is receiving true. It is not receiving the boolValue itself. In the server script, you don't need to make a local value identifying the value to be changed as the server is already receiving it through the remote event. Finally, the first parameter of the server script on server event will always be the client that fired the remote event. Your revised scripts should look something like this:

local remote = game.ReplicatedStorage.sendData
    local valueToChange = workspace.InvetoryBoxes.Invetory1.InvetoryBox1.Occupied

    remote:FireServer(valueToChange)

server

local remote = game.ReplicatedStorage.sendData

remote.OnServerEvent:Connect(function(clientThatFired,valueToChange)
    valueToChange.Value = true
end)

Let me know if you have any questions.

0
I just noticed the difference in boolvalues lol TheB4dComputer 100 — 3y

Answer this question