Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do you pass information in scripts though remote events?

Asked by 3 years ago
Edited 3 years ago

I tried to pass information from the client to the server, but it didn't work. I tried remote events, bindable events, remote functions, bindable functions, but none of them worked. Can someone help me? here is my code for client: `mouse.KeyDown:Connect(function() game.ReplicatedStorage.RemoteEvent:FireServer(brickcolor.new("Really Red") server code: game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(color) workspace.Part.BrickColor = color

1
@Omq_ItzJazmin Isn't the parameter supposed to be input? I know how to use UserInputService, but I use the :GetMouse method, its more easier. But thanks for the help! Finty_james 269 — 3y
0
it can be input, but you can use other variables too like key or button Omq_ItzJasmin 666 — 3y
1
Comment under her answer so she can be notified. You can name parameters anything most people use input but I know some use key instead. radiant_Light203 1166 — 3y
1
I also remebered; I can use ContextActionService, too. Finty_james 269 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

The KeyDown function is deprecated, It's better to use UserInputService instead

https://developer.roblox.com/en-us/api-reference/class/UserInputService

local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(key)
    if key.UserInputType == Enum.UserInputType.MouseButton1 then
        game.ReplicatedStorage.RemoteEvent:FireServer(BrickColor.new("Really Red"))
    end
end)

then your server script:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(color)
    workspace.Part.BrickColor = color
end)
1
What does 'deprecated' mean? NoHaxxxxxxxx 27 — 3y
1
It means that it is no longer supported Finty_james 269 — 3y
1
Thanks Jazmin! But there is one thing you missed after I realized. The player parameter. I have seen this many times. The client automatically Passes the player parameter which is the player who fired the event. So I think I just wanted to let you know. Finty_james 269 — 3y
0
Thank you, so in the second script it would be "OnServerEvent:Connect(function(player,color)" ? Omq_ItzJasmin 666 — 3y
Ad

Answer this question