I am currently making my gun system, (using FastCast module server script for reference, but mine has some changes to fit me) and I need it to fire an event from the server to the client so I can make the hitmaker UI, but its giving the error, “Argument 1 missing or nil” from this part of the script
if hitPart ~= nil and hitPart.Parent ~= nil then
local humanoid = hitPart.Parent:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid:TakeDamage(10) -- damage amount
local repStorage = game:GetService("ReplicatedStorage")
local onHit = repStorage:FindFirstChild("OnHit")
onHit:FireClient()
if humanoid.Health <= 0 then
print(script.Parent.Parent.Name.." killed ".. humanoid.Parent.Name)
--fire event
--local onKill = Tool.OnKill
--onKill:FireClient()
end
end
end
You need to specify what client you want to fire (see RemoteEvent | Roblox Creator Documentation).
1 Like
You need to pass the player
argument in :FireClient()
.
So: onHit:FireClient(player)
Edit: For this script, you would probably want to use :GetPlayerFromCharacter()
2 Likes
That’s what I thought, but its in a server script, how do I get the client from the server
Try this:
local player = game.Players:GetPlayerFromCharacter(hitPart)
2 Likes
It doesnt think its a player,
FireClient: player argument must be a Player object
Try
local player = game.Players:GetPlayerFromCharacter(hitPart.Parent)
1 Like
Correct me if im wrong, wouldnt that be the character you hit instead of the player who shot?
Yeah, you want to get the character or the :GetPlayerFromCharacter()
won’t work.
Edit: It gets the player from the character lol
That is correct. If you want the attacker you need:
local player = game.Players:GetPlayerFromCharacter(tool.Parent)
if player then
print(player)
end
1 Like
This is still a dodgy and error prone method. Before anything you want to confirm what you are using as an argument to :GetPlayerFromCharacter() IS a character.
There are many ways to do this with the easiest being to get the hit part and then check it’s parent and confirm it has a humanoid object inside of it. If it does not, you can go one layer up and check as there are times where say for example you have a part within a part inside of your character or the hit part is an accessory part.
Creating a function which checks the hit part and finds if it’s linked to a character is your best bet.
1 Like
No, I need the player to give them leaderstats later on, and do the hitmarker
I am not using the hitPart. The tool is located inside the character when equipped.
I was referring to your previous post where you referenced hitPart.Parent.
Yeah, thats true in that case.
1 Like
Basically,
In this instance you’d want to get your Character in order for the hit-marker to count on your client side, so you’d probably need to reference the Character
inside the Tool.Activated
event, probably need to do something like this:
local Character = Tool.Parent
local Player = game.Players:GetPlayerFromCharacter(Character)
local Target = game.Players:GetPlayerFromCharacter(hitPart.Parent)
if Player and Target then
local humanoid = hitPart.Parent:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid:TakeDamage(10) -- damage amount
local repStorage = game:GetService("ReplicatedStorage")
local onHit = repStorage:FindFirstChild("OnHit")
onHit:FireClient(Player)
if humanoid.Health <= 0 then
print(script.Parent.Parent.Name.." killed ".. humanoid.Parent.Name)
--fire event
--local onKill = Tool.OnKill
--onKill:FireClient()
end
end
end
4 Likes