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

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

i used script:

 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 :)

1 comment

0

Edit:- code block

1 answer

✓ Accepted answer

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

3 comments

0

ok thx ill try

0

OMG THANKS SOOO MUCH IT WORKS, i love you.

0

i know its gay but i dont care

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