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.
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