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

How is it possible to replicate a string value from client to server?

Asked by 3 years ago
Edited 3 years ago

So right now, I have a localscript:

script.Parent.Frame.Confirm.MouseButton1Click:Connect(function()
    script.Parent.Enabled = false
    game.Workspace.Text.SurfaceGui.TextLabel.Text = script.Parent.Frame.TextProduct.Text .. " $" .. script.Parent.Frame.TextPrice.Text
    game.ReplicatedStorage.Sign.Value = script.Parent.Frame.TextProduct.Text .. " $" .. script.Parent.Frame.TextPrice.Text
end)

I also have a script:

while true do
    print(game.ReplicatedStorage.Sign.Value)
    game.Workspace.Text.SurfaceGui.TextLabel.Text = game.ReplicatedStorage.Sign.Value
    wait(1)
end

When printing, it prints nothing because that is how the string value starts.. It shows up on the client, but when on the server the string value doesn't change. I thought you could change a value on the client and it would replicate to the server in ReplicatedStorage, but I don't know how. How would I do this?

1 answer

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

Use RemoteEvents.

Read this to know more: https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

BTW...

Client:

local remoteEvent = game.ReplicatedStorage.RemoteEvent

script.Parent.Frame.Confirm.MouseButton1Click:Connect(function()    
    remoteEvent:FireServer()
end)

Server:

local remoteEvent = game.ReplicatedStorage.RemoteEvent

remoteEvent.OnServerClient:Connect(function(player)
    script.Parent.Enabled = false
    game.Workspace.Text.SurfaceGui.TextLabel.Text = script.Parent.Frame.TextProduct.Text .. " $" .. script.Parent.Frame.TextPrice.Text
    game.ReplicatedStorage.Sign.Value = script.Parent.Frame.TextProduct.Text .. " $" .. script.Parent.Frame.TextPrice.Text
end)

^Make sure ServerScript and LocalScript have the same parent ig or just modify the locations in the script if that isn't possible.

Ad

Answer this question