I am trying to make a grappling gun in Roblox and my RemoteEvent is not working. Here is the local script
local RS = game:GetService("ReplicatedStorage") local held = RS:WaitForChild("held") local Player = game.Players.LocalPlayer local Character = Player.Character local GrapplePart = game.Workspace:WaitForChild("GrapplePart") local Click = false local mouse = game.Players.LocalPlayer:GetMouse() local UIS = game:GetService("UserInputService") local RS = game:GetService("ReplicatedStorage") UIS.InputBegan:Connect(function(input) local inputType = input.UserInputType if inputType == Enum.UserInputType.MouseButton1 then Click = true held:FireServer(mouse, true) print("On") end end)
and this is the server script
held.OnServerEvent:connect(function(player, mouse, value) print("It worked") --Nothing shows up in the output end)
Okay, so I think I see what the problem is. Here's a list of things you should check...
- GrapplePart doesn't exist in workspace? And since it's using :WaitForChild, the local script will infinitely wait until it find this part, meaning it won't run the rest of the code until GrapplePart is found. So don't add variables that you aren't going to use or it doesn't exist yet.
local GrapplePart = game.Workspace:WaitForChild("GrapplePart")
You might be placing the scripts in the wrong service. Make sure your SERVER script is in the ServerScriptService, and your LOCAL script is either in the StarterGui or StarterPlayerScripts.
In your server script, you need to recall ReplicatedStorage and search for "held". Because you're doing (held.OnServerEvent), and held is never defined in the server script.
Here's your code cleaned up
Local Script
local RS = game:GetService("ReplicatedStorage") local held = RS:WaitForChild("held") local Player = game.Players.LocalPlayer local Character = Player.Character local Click = false local mouse = game.Players.LocalPlayer:GetMouse() local UIS = game:GetService("UserInputService") UIS.InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton1 then Click = true held:FireServer(mouse, true) print("On") end end)
Server Script
local RS = game:GetService("ReplicatedStorage") local held = RS:WaitForChild("held") held.OnServerEvent:connect(function(player, mouse, value) print("It worked") --Nothing shows up in the output end)