So I made a server sided raycasting weapon but because the rays were delayed - I'm trying to remake it to client sided. I'm creating client sided rays and once a ray hits a player - it fires server to deal damge.
The problem is that I can't figure out how to get the player that was hit from the client side to be known on the server side. I tried passing the player name as an argument but the output on the server side prints that the name is nil.
Here's a short version of the local script:
local player=game.Players.LocalPlayer
local mouse=player:GetMouse()
local character=player.Character or player.CharacterAdded:wait()
mouse.Button1Down:Connect(function()
local model=character:FindFirstChildOfClass'Model'
local ray=Ray.new(model.Hole.Position,(mouse.Hit.p-model.Hole.Position).unit*100)
local hit,position=workspace:FindPartOnRay(ray,player.Character,false,true)
if hit~=nil and hit.Parent:FindFirstChild'Humanoid'then
local argument=hit.Parent.Name
game.ReplicatedStorage.RemoteEvent:FireServer('Damage',argument)
end
end)
And the server script:
local remoteevent=game.ReplicatedStorage.RemoteEvent
remoteevent.OnServerEvent:Connect(function(player,variant,argument)
if variant=='Damage'then
workspace.argument.Humanoid:TakeDamage(10)
end
end)
Thank you if you're still here =)
