#ServerScriptService.GunHandler:11: attempt to index nil with 'Position'

24 messages · Page 1 of 1 (latest)

urban nimbus
#

I got this error for some reason on my gun script. It used to work but now its changed somehow. Idk how to fix it. It can't find the position of the handle.

local mouse = player:GetMouse()
local Tool = script.Parent

local cooldown = false
local cooldownTime = 0.1

local function Pew()
    Tool.Handle.PointLight.Enabled = true
    local pew = Tool.Handle.pew
    pew:Play()
    game.ReplicatedStorage.ShootGun:FireServer(Tool.Handle)
end

local function Shoot()
    -- Function code
    
    if cooldown == true then
        return
    end
    
    cooldown = true
    Pew()
    
    print("Firing")
    
    wait(cooldownTime)
    cooldown = false
    Tool.Handle.PointLight.Enabled = false
    
end

Tool.Activated:Connect(function()
    -- Will run when player clicks with weapon equipped
    
    Shoot()
    
end)``` Local script in the tool
#
local damage = 20

game.ReplicatedStorage.ShootGun.OnServerEvent:Connect(function(Player, TargetLocation, Handle)
    if Player.Character == nil then -- Make sure the character exists
        return
    end

    local newBullet = game.ReplicatedStorage.Bullet:Clone()
    newBullet.Parent = game.Workspace
    newBullet.Position = Handle.Position
    newBullet.CFrame = CFrame.new(Handle.Position, TargetLocation)
    local direction = (TargetLocation - newBullet.Position).unit
    newBullet.Velocity = direction * range
    
    -- Make it so that when the bullet touches a humanoid that is not the player shooting, that it damages it
    newBullet.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= Player.Character then
            hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - damage
            newBullet:Destroy()
        end
    wait(5)
    newBullet:Destroy()
    
    end)
end)``` Script in sss
#

The error is at newBullet.Position = Handle.Position

#

It can find the handle but when it comes to the position it can't find it even tho it used to before

#

from what i've learned

#

game.ReplicatedStorage.ShootGun:FireServer(Tool.Handle) This passes over the handle

#

and it seems to be that since i could find the handle but

#

it didnt pass over the position like it used to

shrewd mauve
#

The handle is only on the client, so the server can not find it

urban nimbus
#

wait hold up I think i figured it out

#

yea i just realized why

#

it was suppost to pass over the position but when I was making my sword script I tried to use this script for it and ended up removing the position

#

ty 🙂

#

another thing that is weird that i just found

#

hold up

#

so

#

when i have like a tool equipped and i press shift and w as if i was tryna run and then try to equip another tool at the same time

#

everything just stops working until i click the screen

#

i stop running or moving anything

#

i'm locked in the position pretty much

#

it seems to be cause the shift part

#

idk why

#

nvm figured it out

#

shift + 2 is a shortcut