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

01local RS = game:GetService("ReplicatedStorage")
02local held = RS:WaitForChild("held")
03local Player = game.Players.LocalPlayer
04local Character = Player.Character
05local GrapplePart = game.Workspace:WaitForChild("GrapplePart")
06local Click = false
07local mouse = game.Players.LocalPlayer:GetMouse()
08local UIS = game:GetService("UserInputService")
09local RS = game:GetService("ReplicatedStorage")
10UIS.InputBegan:Connect(function(input)
11   local inputType = input.UserInputType
12   if inputType == Enum.UserInputType.MouseButton1 then
13        Click = true
14        held:FireServer(mouse, true)
15        print("On")
16    end
17end)   

and this is the server script

1held.OnServerEvent:connect(function(player, mouse, value)
2    print("It worked") --Nothing shows up in the output
3end)
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.
1local 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

01local RS = game:GetService("ReplicatedStorage")
02local held = RS:WaitForChild("held")
03local Player = game.Players.LocalPlayer
04local Character = Player.Character
05local Click = false
06local mouse = game.Players.LocalPlayer:GetMouse()
07local UIS = game:GetService("UserInputService")
08 
09UIS.InputBegan:Connect(function(input)
10   if input.UserInputType == Enum.UserInputType.MouseButton1 then
11        Click = true
12        held:FireServer(mouse, true)
13        print("On")
14    end
15end)

Server Script

1local RS = game:GetService("ReplicatedStorage")
2local held = RS:WaitForChild("held")
3 
4held.OnServerEvent:connect(function(player, mouse, value)
5    print("It worked") --Nothing shows up in the output
6end)
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