Why does it appear as nil when I try to locate my gun so I can fire an event on the server side

I have this code “Note this is only a part of the code, tell me if you need more.”

UserInput.InputBegan:Connect(function(input, typing, gameProcessedEvent)
if SlotTwoActive == true then
if typing == false then
if InAction == false then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
InAction = true
AnimationStopOverHull(“Aim”)
AnimationStopOverHull(“Idle”)
if AimedIn == true then
Humanoid:LoadAnimation(PistolAnims:FindFirstChild(“Shoot”)):Play()
delay(0,function()
Rep.RemoteEvents.Fire:FireServer(Char.DRGPistol,“rbxassetid://5805894981”)
end)
wait(0.25)
Humanoid:LoadAnimation(PistolAnims:FindFirstChild(“Aim”)):Play()
else
Humanoid:LoadAnimation(PistolAnims:FindFirstChild(“ShootUnaimed”)):Play()
delay(0,function()
Rep.RemoteEvents.Fire:FireServer(Char.DRGPistol,“rbxassetid://5805894981”)
end)
wait(0.5)
Humanoid:LoadAnimation(PistolAnims:FindFirstChild(“Idle”)):Play()
end

									InAction = false
								end

When ever I do this command in the script “Rep.RemoteEvents.Fire:FireServer(Char.DRGPistol,“rbxassetid://5805894981”)”

im firing on an event so that the server can make a shooting effect on the gun,
but it keeps sending the part that says “Char.DRGPistol” as nil. Yet this is a model in the players character.

here is my server sided script that fires off of the event


Rep.RemoteEvents.Fire.OnServerEvent:Connect(function(plr,Gun,Soundid)
local Char = plr.Character print(Char)
print(Gun)
local Flash = Rep.GunEffects:FindFirstChild(“NuzzleFlash”):Clone()
local Weld = Instance.new(“Weld”)
local Sound = Instance.new(“Sound”) print(Sound)

Flash.Parent = Char
Flash.Position = Char.HumanoidRootPart.Position

Sound.Parent = Flash
Sound.SoundId = Soundid
Sound:Play()
wait(1)
Flash:Destroy()
print("Fired")

end)


And whenever it prints “Gun” it prints nil and so I can’t move the effect to the Guns Nuzzle.

Have any solutions?

Does the gun exist on the server? This could be because you create the weapon on the client so it doesn’t exist on the server.

1 Like

Huh, I guess it is not cloned on the server, Thanks. should I just clone it from the server and it will fix the problem?

Yes, if you create the weapon on the server instead of the client this will solve your problem hopefully.

1 Like