When I run the code locally it works well but when I run it on a server, it does not recognize the mouse. I am pretty new to filtering enabled and I need help. Side note: the damage does not work either.
Local script:
h = script.Parent.Handle script.Parent.Activated:Connect(function() game.ReplicatedStorage.RemoteEvent:FireServer(h) end)
Server script:
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr, handle) local m = plr:GetMouse() local b = Instance.new("Part",game.Workspace) b.Shape = "Ball" b.BrickColor = BrickColor.new("Really red") b.Size = Vector3.new(1,1,1) b.CFrame = CFrame.new(handle.Position, mouse.hit.p) local v = Instance.new("BodyVelocity",b) v.Velocity = b.CFrame.lookVector * 400 v.MaxForce = Vector3.new(math.huge,math.huge,math.huge) local d = game:GetService("Debris") d:AddItem(b, 5) b.Touched:connect(function(hit) if hit ~= handle then local h = hit.Parent:FindFirstChild("Humanoid") if h then if h.Parent.Name ~= plr.Name then h:TakeDamage(10) end end end end) end)
Hit
and Target
as parameters, though.local ReplicatedStorage = game:GetService("ReplicatedStorage") local Remote = ReplicatedStorage:WaitForChild("RemoteEvent") Remote.OnServerEvent:Connect(function(plr,handle,hit) local b = Instance.new("Part") -- parent argument is deprecated and slows down game performance, assign in another line b.Shape = Enum.PartType.Ball -- assign as enums, makes it faster b.BrickColor = BrickColor.new("Really red") b.Size = Vector3.new(1,1,1) b.CFrame = CFrame.new(handle.Position, hit.p) b.Parent = game.Workspace -- the parent should always be the last thing to assign local dmgScript = script.DmgScript:Clone() -- the touched event script is a separate script dmgScript.Parent = b dmgScript.Disabled = false -- manually set disabled to true first, we then enable it local v = Instance.new("BodyVelocity") v.Velocity = b.CFrame.lookVector * 400 v.MaxForce = Vector3.new(math.huge,math.huge,math.huge) v.Parent = b local d = game:GetService("Debris") d:AddItem(b, 5) end)
DmgScript
script.Parent.Touched:Connect(function(hit) -- :connect is deprecated, switch to :Connect if hit.Name == "Handle" then return end -- if a handle, stop function local h = hit.Parent:FindFirstChild("Humanoid") if h then h:TakeDamage(10) end end end)
local plr = game:GetService("Players").LocalPlayer local mouse = plr:GetMouse() local h = script.Parent.Handle script.Parent.Activated:Connect(function() game.ReplicatedStorage.RemoteEvent:FireServer(h, mouse.Hit) -- Hit not hit end)
I would suggest passing the mouse from the client alongside everything else. To do that, just create another argument in your server script.
I'm calling it "m" since that's what you call the mouse in your script previously
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr, handle, m)
& pass it along from the client: (localscript)
local lp = game.Players.LocalPlayer game.ReplicatedStorage.RemoteEvent:FireServer(h, lp:GetMouse())
Delete the "local m = plr:GetMouse()" line from your server script.
Your final LocalScript code should look like this:
local h = script.Parent.Handle local lp = game.Players.LocalPlayer script.Parent.Activated:Connect(function() game.ReplicatedStorage.RemoteEvent:FireServer(h, lp:GetMouse()) end)
And your serverscript code should look like this:
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr, handle, m) -- we no longer need to use GetMouse(), since it's already passed local b = Instance.new("Part",game.Workspace) b.Shape = "Ball" b.BrickColor = BrickColor.new("Really red") b.Size = Vector3.new(1,1,1) b.CFrame = CFrame.new(handle.Position, mouse.hit.p) local v = Instance.new("BodyVelocity",b) v.Velocity = b.CFrame.lookVector * 400 v.MaxForce = Vector3.new(math.huge,math.huge,math.huge) local d = game:GetService("Debris") d:AddItem(b, 5) b.Touched:connect(function(hit) if hit ~= handle then local h = hit.Parent:FindFirstChild("Humanoid") if h then if h.Parent.Name ~= plr.Name then h:TakeDamage(10) end end end end) end)
Note: I made it pretty copy-paste friendly, and I'm sorry for that. Please read over what I've said and not just copy and paste if it does end up working.