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

How to use remote events to make keydown do something to server?

Asked by 5 years ago
Edited by User#5423 5 years ago

i used script:

```lua local Player = script.Parent.Parent

local Character = Player.Character or Player.CharacterAdded:Wait()

local Humanoid = Character:WaitForChild("Humanoid")

local HumaoidRP = Character:WaitForChild("HumanoidRootPart")

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(Input)

if Input.KeyCode == Enum.KeyCode.G then

print("bag droped")

game.ReplicatedStorage.remote:FireServer(game.Workspace.Baseplate:Destroy())

end

end) ``` and i used fire SERVER, but baseplate only removed for client, (player pressing g) why? please fix it :)

0
Edit:- code block User#5423 17 — 5y

1 answer

Log in to vote
1
Answered by
gullet 471 Moderation Voter
5 years ago
Edited 5 years ago

You can't pass the code you want to execute as a parameter, you'll have to listen for the event being fired on the server (Script) and execute that code there. So just do game.ReplicatedStorage.remote:FireServer() and on the server

game.ReplicatedStorage.remote.OnServerEvent:Connect(function(plr)
    print(plr.Name, "destroyed the basepalte")
    game.Workspace.Baseplate:Destroy()
end

Further reading: https://developer.roblox.com/api-reference/class/RemoteEvent

0
ok thx ill try CommanderCaubunsia 126 — 5y
0
OMG THANKS SOOO MUCH IT WORKS, i love you. CommanderCaubunsia 126 — 5y
0
i know its gay but i dont care CommanderCaubunsia 126 — 5y
Ad

Answer this question