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

Edit serverside StringValue from LocalScript?!

Asked by 5 years ago
Edited 5 years ago

I have been trying to make a cash register for a game and I want to store the name of the cashier into a StringValue.

Code: (LocalScript)

plr = game.Players.LocalPlayer

add = function() -- local add = function() doesn't work either
    script.Parent.Parent.Parent.Parent.CustomerSide.Frame.LastAdded.Text = "Last added: " .. script.Parent.ItemName.Value
    script.Parent.Parent.Parent.Cashier.Value = plr.Name
    print(plr.Name)
end

script.Parent.ImageButton.MouseButton1Click:connect(add)
script.Parent.TextButton.MouseButton1Click:connect(add)

This code doesn't execute add() for some reason

EDIT: Using a regular Script instead of LocalScript does execute add() but it doesn't work with game.Players.LocalPlayer

2 answers

Log in to vote
1
Answered by
mattscy 3725 Moderation Voter Community Moderator
5 years ago

Local scripts cannot change values on the server, as any changes made will only appear to happen for that client due to the client server model. To fix this, you can look into sending a remote event to the server to update the value from a server script.

Ad
Log in to vote
0
Answered by 5 years ago
plr = game.Players.LocalPlayer

function add() -- local add = function() doesn't work either
    script.Parent.Parent.Parent.Parent.CustomerSide.Frame.LastAdded.Text = "Last added: " .. script.Parent.ItemName.Value
    script.Parent.Parent.Parent.Cashier.Value = plr.Name
    print(plr.Name)
end

script.Parent.ImageButton.MouseButton1Click:connect(add)
script.Parent.TextButton.MouseButton1Click:connect(add)

Try now??

0
Still nothing BeAHacker666 75 — 5y
0
when I use this is a normal script it works except I can't use game.Players.LocalPlayer BeAHacker666 75 — 5y

Answer this question