Search code examples
luagame-developmentroblox

Roblox Studio, how do I send a string through a remote event


This is the local script

button.Activated:Connect(function()
        remoteEvent:FireServer(button.Text.Text)
        game.Workspace.DimensionConfig.Value.Value = button.Text.Text
        
        
    end)

Here is the server script in Workspace.

local function changeValue(Name)
print("Did that")
print(Name)
game.Workspace.DimensionConfig.Value.Value = Name
end
remoteEvent.OnServerEvent:Connect(changeValue)

Then output

Did that  -  Server - Script:5
(my username)  -  Server - Script:6
  Unable to assign property Value. string expected, got Instance 

I don't know why it prints my username.


Solution

  • You just forgot to have a player paramiter instead. Change your code to this

    local function changeValue(player, Text)
    print("Did that")
    print(player)
    print(Text)
    -- Prints the player Name and text being sent.
    game.Workspace.DimensionConfig.Value.Value = Text
    end
    remoteEvent.OnServerEvent:Connect(changeValue) 
    

    That should work. With remote events always make sure to add a "Player" parameter to the event function. When firing a remote event to be received server side. The Server always needs to know who sent it.