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

How to make value replicate to server?

Asked by 2 years ago

I have this object value that determines what the player currently has equipped, but I'm trying use it in scripts on the server side. The problem is that the value is being set on the client side, and on the server side, it is set to nil. I tried making a script to set in on the server side but it doesn't work.

The script that should set in on the server side:

local event = game.ReplicatedStorage.invEquip

event.OnServerEvent:Connect(function(player, set)
    print(set)
    print(player)
    game.ReplicatedStorage.equipped.Value = set
end)

In this script, player is the actual player, and set is what I want to set the value to. Problem is that it says set is nil although it shouldn't be.

Here is the client-side code:

local equipedValue = game.ReplicatedStorage.equipped
local invEquip = game.ReplicatedStorage.invEquip
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    if equipedValue.Value == script.Parent then
        invEquip:FireServer(nil)
        equipedValue.Value = nil
        equipedValue.ImageLabel.Image = ("")
    elseif equipedValue.Value ~= nil then
        local success = game.ReplicatedStorage.craftFunction:Invoke(equipedValue.Value, script.Parent) 
        if success then
        end
    else
        equipedValue.Value = script.Parent
        invEquip:FireServer(script.Parent)
        -- this is what is being fired
    end
end)


0
I'd say to just cut out the client script and use server? CraftyAlphaMan 11 — 2y

Answer this question