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

Why isn't hole a valid member of tool?

Asked by 5 years ago
Edited 5 years ago

Im trying to make a gun to my game, and i made this script:

-- Algumas variaveis --
local pistola = script.Parent
local hole = pistola.Hole
local mouse = game.Players.LocalPlayer:GetMouse()

-- Lista de Valores --
local ammo = 12
local maxAmmo = 64
local damage = 20
local headshotDamage = 50
local range = 100
local coolDown = 0.5

-- impedir spamming --
local spam = false

-- Mudar o rato --
pistola.Equipped:Connect(function()
    mouse.Icon = "rbxassetid://358948941"
end)

pistola.Unequipped:Connect(function()
    mouse.Icon = ""
end)

-- Disparo --
pistola.Activated:Connect(function()
    if spam == false then
         spam = true
        pistola.Handle.Disparo:Play()
       local bullet = Instance.new("Part")
       bullet.Size = Vector3.new(range,0.25,0.25)
       local ray = Ray.new(hole.CFrame.Position, (mouse.Hit.Position - hole.CFrame.Position).Unit*range)
       local hit, position = workspace:FindPartOnRay(ray, game.Players.LocalPlayer.Character)
       local distance = (pistola.Handle.CFrame.p - position).magnitude
       bullet.CFrame = CFrame.new(pistola.Handle.CFrame.p, position) * CFrame.new(0,0, distance/2)
       bullet.Transparency = 0.5
       bullet.CanCollide = false
       bullet.Anchored = true
       bullet.Parent = game.Workspace
       bullet.Orientation = hole.Orientation
       bullet.Position = hole.Position
    game:GetService("Debris"):AddItem(bullet, 0.5) 
        spam = false
    end 
end)

Ignore the parts were i speak portuguese :P But then i start recieving this error: 18:30:18.806 - Hole is not a valid member of Tool

idk what's happening, could you pls help me?

Also send a real answer, not a comment.

0
What is hole and is it a child of what ever script.Parent is? xPolarium 1388 — 5y
0
it's either the hole didn't load in or the hole isn't a child of Tool, if it is, try using pistola:WaitForChild("Hole") theking48989987 2147 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Hole probably dosen't exist inside the Tool

If it is try this:

pistola:WaitForChild("Hole")

0
ok mewant_taco 17 — 5y
0
Thank you :D mewant_taco 17 — 5y
Ad

Answer this question