Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use TextBox input to change a value by firing a RemoteEvent

I’ve been trying to figure this out for about 30 minutes and have had no luck. I’m stumped and cannot figure this out.

I am trying to make a script that allows the player to change their money by inputting a number into their TextBox.

Local Script (child of TextBox)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

script.Parent.FocusLost:Connect(function(enter)
    if enter then
        -- this is to check the player's input
        local finalvalue = tonumber(script.Parent.Text)
        print(script.Parent.Text)
        -- if it was not a number
        if finalvalue == nil then
            script.Parent.Text = "Not a number"
            wait(1)
            -- just making sure that it doesn't delete the player's new input
            if script.Parent.Text == "Not a number" then
                script.Parent.Text = ""
            end
        else
            -- firing the money remote event with the finalvalue variable
            game.ReplicatedStorage.ChangeMoney:FireServer(finalvalue)
            print("fired")
            -- resetting the textbox
            script.Parent.Text = ""
        end

    end
end)

Server Script (child of ServerScriptService)

game.ReplicatedStorage.ChangeMoney.OnServerEvent:Connect(function(amt)

    game.ReplicatedStorage.Money.Value = tonumber(amt)
    print("money changed to " .. tostring(amt))
end)

Thank you.

>Solution :

The problem is that OnServerEvent receives a Player in addition to a tuple of arguments passed by FireServer().

It looks like there is just one money value for the entire server, so assuming that the value you’re trying to change is independent of the player who sent the RemoteEvent, you can just change your function declaration to accept the Player and just disregard it after that:

game.ReplicatedStorage.ChangeMoney.OnServerEvent:Connect(function(player, amt)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading