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

How can I send a StringValue through a remote event?

I want to send the value of a stringvalue to the server in a Remote Event whenever the string value changes. But I don't how to send it to the server and how to get the server to recieve it.

Firing localscript

local ServerStorage = game.ServerStorage

script.Parent.Changed:Connect(function()--string value
    ServerStorage.EmoteGrabber:FireServer()
end)

finding script

local ServerStorage = script.Parent

local EmoteList = require(ServerStorage.EmoteList)

local EmoteGrabber = ServerStorage.EmoteGrabber

EmoteGrabber.OnClientEvent:Connect(function(Player)--Problem here is that the server will get the player but not the string value too
	

	--yes there's nothing here atm because i need to save the string value as a variable
end)

1 comment

0

The whole point of a remote event is so the client can access the server. So trying to access server storage with the client is impossible. That’s why there is replicated storage.

2 answers


game.ReplicatedStorage.emotegrabber:FireServer(“Hello”)

Then in server script:

game.ReplicatedStorage.emotegrabber.OnServerEvent:Connect(function(player, stringValue) end)

You also could replace “hello” with a variable that holds a string.StringValue doesn’t have to be called that, it can be called variable, or whatever you want it to be. I just used that to show you that’s what it was.

Also when you want to send through remote events from client to server you have to put a remote event in replicated storage. In your case you would rename the remote event emotegrabber.

It’s a server event because it’s happening on the server so change it to OnServerEvent. To fire to the server you say FireServer. To fire to the client you say FireClient or whatever that is lol. To fire to all clients you say FireAllClients. If it’s happening on the clients side you would say OnClientEvent.

1 comment

0

Please indicate if this solved your problem. It should have.

Hello.


You'd need to pass the value of the string to the server. This is easy. Just use the argument of FireServer(). The StringValue instance will get fired to the server as "ChangedValue".

Why don't you send the string as a value in the argument you may ask. This is to prevent exploiters. Exploiters can easily change mostly everything on the client. But as you probably know, due to FilteringEnabled, anything that happens on the client will NOT happen on the server.

After that, the server will set "ChangedValue" to the value of the StringValue object.


You also used OnClientEvent on a ServerScript. Instead, use OnServerEvent as OnClientEvent is for LocalScripts only.


Fixed LocalScript:

local ServerStorage = game.ServerStorage

script.Parent.Changed:Connect(function()--string value
    ServerStorage.EmoteGrabber:FireServer(script.Parent)
end)

Fixed ServerScript:

local ServerStorage = script.Parent

local EmoteList = require(ServerStorage.EmoteList)

local EmoteGrabber = ServerStorage.EmoteGrabber

EmoteGrabber.OnServerEvent:Connect(function(Player, ChangedValue)
	ChangedValue = ChangedValue.Value
end)

2 comments

0

I had changed the parents of all objects that i'm using to ReplicatedStorage because the localscript is unable to see the children of ServerStorage. The remote event doesn't fire, or it's not receiving it. I put a print in the OnServerEvent function and it doesn't run, so I think the serverscript isn't receiving it. But why? Can you help me out?

0

 ScPut the script in ServerScriptService, not ServerStorage. Scripts don't run inside ServerStorage

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