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 4 years ago
Edited 4 years ago

So right now, I have a localscript:

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

I also have a script:

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

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 4 years ago
Edited 4 years ago

Use RemoteEvents.

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

BTW...

Client:

1local remoteEvent = game.ReplicatedStorage.RemoteEvent
2 
3script.Parent.Frame.Confirm.MouseButton1Click:Connect(function()   
4    remoteEvent:FireServer()
5end)

Server:

1local remoteEvent = game.ReplicatedStorage.RemoteEvent
2 
3remoteEvent.OnServerClient:Connect(function(player)
4    script.Parent.Enabled = false
5    game.Workspace.Text.SurfaceGui.TextLabel.Text = script.Parent.Frame.TextProduct.Text .. " $" .. script.Parent.Frame.TextPrice.Text
6    game.ReplicatedStorage.Sign.Value = script.Parent.Frame.TextProduct.Text .. " $" .. script.Parent.Frame.TextPrice.Text
7end)

^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