How to change the value with a normal script in a textbutton?

My problem is that this script does not send any signal, to the stringValue, and it does not give me any solution

local aceptar = script.Parent:WaitForChild("BAceptar")

local cancelar = script.Parent:WaitForChild("CCancelar")

local Players = game:WaitForChild("Players")

local Value = script.Parent.Parent:WaitForChild("Abrir")

game.Players.PlayerAdded:Connect(function(player)

aceptar.MouseButton1Click:connect(function(obj)

Value.Value = player.Keys.MenuKey.Value

end)

end)
1 Like

This script is full of errors.

You don’t need the Players function if you do

game.Players.PlayerAdded:Connect(function(player)

end)

and to check if a button is clicked you don’t need the PlayerAdded function but just:

aceptar.MouseButton1Click:Connect(function()
    Value.Value = player.Keys.MenuKey.Value
end)

Is this a local script or server script? And where is it located?

“Players” is not an instance, therefore you can’t use WaitForChild nor FindFirstChild or anything like that. It’s a service, retreivable through GetService.

local Players = game:GetService('Players')

Really really hoping this is a local script, not a server script, because if it is you can simply fetch the player easily with LocalPlayer.

local Player = Players.LocalPlayer -- 'Players' is the variable we defined earlier

aceptar.MouseButton1Click:Connect(function()
    print('working!')
    -- Your other code
end)

I’ll be able to help you further if you give more information

It is a server script, because I don’t know if with a localScript the value data can be saved with datastore

I would suggest for you to make this a local script. Where is it located?

I’d strongly advise avoiding the use of server scripts in UI, just utilize RemoteEvents to pass params through the server/client boundary. That way, when you fire to the server, the data can save through there.

The script is totally messed up with errors.

You can make a folder in replicated storage for remote events, and a local script does not do anything with player joined.You need a server sided script in server script service.

And you could do something like:

game.Players.PlayerAdded:Connect(function(player)
    local remotevent = game.ReplicatedStorage:WaitForChild("RemoteEvent")
    remotevent:FireClient(player)
end)

So this is the script from server script service.As local script is a script basically used by clients.It will spawn after a client joined so it does not matter if you keep as it does not work with a local script.

If you want to do anything in your game, make sure you make it server sided if you want everyone to see it and its a server sided change.

Did this help you?
  • Yes
  • A bit
  • No not at all
  • Yes I understood now

0 voters

Well, let me explain if you can help me. I made a key changing system, in case you didn’t like how the key was arranged, you could change it, but I want it to be saved by pressing a TextButton using the datastore, but I already have the dataStore as well but it doesn’t detect the value, I already made another post on that topic, but they say it’s broken and I don’t really know what to do anymore