I'm trying to hurt the player but I can't do this locally because of Filtering Enabled.
Error message: Unable to cast Instance to float | Script 'Workspace.GlobalInstances', Line 2
--receiving script
Sending script/Local:
local clickdeb = true mouse.Button1Down:connect(function() if clickdeb then clickdeb = false if CheckAmmo() then currentamount = currentamount - 1 spawn(function() bulletflash() updateammo() wait(.2) shootgui() end) local bullet = shootbullet(shooter.CFrame.p, mouse.Hit.p) local hit = ray(shooter.CFrame * CFrame.new(0,0,1), mouse.Hit.p) local damage = math.random(dmgmin,dmgmax) if hit then if hit.Name == "Head" then damage = damage * 3 end game.Workspace.GlobalInstances.HurtPlayer:FireServer(hit.Parent,damage) print("youshotsomething") end end wait(betweenshot) clickdeb = true end end)
Normal script/Reciver:
script.HurtPlayer.OnServerEvent:connect(function(playertohurt,amount) game.Workspace[playertohurt.Name].Humanoid:TakeDamage(amount) end)
View script in source to see the full thing
Your problem is a simple one I make a lot. The arguments for the OnServerEvent function are first 'player', representing the player who sent it, and then the arguments you passed.
Example
LocalScript
RemoteEvent.FireServer(1, "A")
ServerScript
RemoteEvent.OnServerEvent:connect(function(player, number, letter) print(player, number, letter) end) -- Output: playerWhoFiredEvent, 1, A
Solution
Your fix is to simply add one more argument to the OnServerEvent function:
script.HurtPlayer.OnServerEvent:connect(function(player, playertohurt, amount) game.Workspace[playertohurt.Name].Humanoid:TakeDamage(amount) end)