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

Can't transfer player name through a remote event?

Asked by
aiuis 85
6 years ago
Edited 6 years ago

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 =)

1 answer

Log in to vote
1
Answered by
Asceylos 562 Moderation Voter
6 years ago
Edited 6 years ago

The error is probably that you just did workspace.argument.

local remoteevent=game.ReplicatedStorage.RemoteEvent

remoteevent.OnServerEvent:Connect(function(player,variant,argument)
    if variant=='Damage'then
        workspace:FindFirstChild(argument[1]).Humanoid:TakeDamage(argument[2])
    end
end)
Ad

Answer this question