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

RemoteEvents not working! what am I doing wrong? Concise answer

Asked by 4 years ago

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)
0
The reason I said concise answer is because it said describe your problem concisely Longjohnnn 28 — 4y
0
fire the mouse position instead, tell me if there are errors.. try using mouse.Button1Down instead maybe greatneil80 2647 — 4y
0
There were no errors before but when I did mouse.position and with Button1Down there is an error message sayingPlayers.longjohnnn.PlayerScripts.LocalScript:30: Expected ')' (to close '(' at line 10), got 'end' the error message is at the end of the script on line 17 but when I highlight the bracket at the end it is the ending one to the one at line 10 so I am confused. Longjohnnn 28 — 4y
0
But, as you can see, I put print("On") whenever the mouse was clicked and it printed that. But the server one didn't. Longjohnnn 28 — 4y
View all comments (2 more)
0
So, all in all from my observation, the way that I first detected that the mouse was clicked worked. But I could have also been doing it wrong. Longjohnnn 28 — 4y
0
you forgot an ) on the end on the third comment, thats what the error was for, try changing connect to Connect and define held on the server script if you didnt greatneil80 2647 — 4y

1 answer

Log in to vote
0
Answered by
Yozoh 146
4 years ago

Okay, so I think I see what the problem is. Here's a list of things you should check...

  1. 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")
  
  1. 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.

  2. 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)
0
Oh my gosh I'm so stupid, I accidentally put the script in ServerStorage instead of ServerScriptService lol. Thank you. Longjohnnn 28 — 4y
Ad

Answer this question