Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Edit serverside StringValue from LocalScript?!

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

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.

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??

2 comments

0

Still nothing

0

when I use this is a normal script it works except I can't use game.Players.LocalPlayer

This discussion is preserved as it was. New answers, comments, and votes are closed.