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

Need Help With Remote Events And Detecting Input | Any Ideas?

Asked by 6 years ago
Edited 6 years ago

I've been struggling with this problem for a few days now, and I'm wondering if the problem is from me not having scripts/remote events in the right places. While in studio, my scripts are detecting my clicks and doing exactly what they are supposed to after the player clicks. When I play as a user on the Roblox servers, nothing works at all.

Anyway, I scripted my own axe to deal damage to trees after my remote event, "PlayerClicked" (located in Replicated Storage) is fired.

Here is the bit where it gets handled in the axe script:

local clickEvent = game.ReplicatedStorage.RemoteEvents.PlayerClicked   
-- RemoteEvents is a folder

clickEvent.OnServerEvent:Connect(function()
    Clicked()    -- Function that deals damage, etc.
end)

And here is the script that detects the click and fires the remote event:

local Player = game.Players.LocalPlayer --get the local player
local Mouse = Player:GetMouse() --get the mouse

Mouse.Button1Down:connect(function()
    game.ReplicatedStorage.RemoteEvents.PlayerClicked:FireServer()
end)

The script detecting the clicks is a local script located in StarterGui, and the axe script is a server script located on the axe tool.

I can't figure this out for the life if me. If someone could point me in the right direction, I would be very grateful!

After some debugging, I've narrowed the problem down a little. The listener for user input in the local script is working perfectly fine, It might not be firing the RemoteEvent though and that still leaves the server script as well. I still have no idea where the error is occurring.

As a side note, disabling filtering has no effect.

1 answer

Log in to vote
-1
Answered by 6 years ago
Edited 6 years ago

Hmm, your script looks fine. TO me it does. But try adding the arguments "game.Players.LocalPlayer" and "Player" Like this.

local clickEvent = game.ReplicatedStorage.RemoteEvents.PlayerClicked
local Player = game.Players.LocalPlayer   
--Server Script
-- RemoteEvents is a folder

clickEvent.OnServerEvent:Connect(function(Player)
    Clicked()    -- Function that deals damage, etc.
end)

--This is the localscript, the script that is firing the remoteevent to the player! You set the remote event's function to do whatever you wanted it to do, in the serverscript. 
local Player = game.Players.LocalPlayer --get the local player
local Mouse = Player:GetMouse() --get the mouse

Mouse.Button1Down:connect(function()
    game.ReplicatedStorage.RemoteEvents.PlayerClicked:FireServer(game.Players.LocalPlayer)
end)

Hopefully it helps! I'm not sure what the exact problem is but I'm just guessing to fire it to the Player's localplayer. Make sure that the Server script that is giving the OnServerEvent function to the remoteevent is in the ServerScriptService and that the LocalScript that is firing your remoteevent is in the StarterPlayerScripts. Normally, you could put the Localscript anywhere. But that's not the case, you need to put it in a folder that handles Players. StarterGui, StarterCharacter or StarterPlayerScripts. I recommend StarterPlayerScripts. I hope you succeed and find a way to fix what you are trying to solve, and have a good day in scripting :P

0
LocalPlayer is nil on the server. User#19524 175 — 6y
0
Facepalm, that's why we use the argument game.Players.LocalPlayer when firing the remoteevent. That's also why we use the argument "Player" in the ServerScript. User#21998 0 — 6y
0
Not sure what exactly you are trying to solve here.... but passing through the player as a parameter wouldn't change anything. I don't need the player reference anymore after the click has been detected and the server script fired. pick1ehead 53 — 6y
Ad

Answer this question