Ad
Log in to vote
0

"Handle is not a valid member of tool" - Error????

Asked by 2 years ago

I have two weapons I've made & scripted using the same fashion for both. One works completely fine (M1911) & the other (Ak-47) doesn't work at all. Now I know its because of this one error that keeps popping up, "Handle is not a valid member of tool"? I have a handle inside of my tool exactly like my M1911 which works just fine. Now note my Ak did work at one point before I tried adding sound effects for, equip, reload, magazine in, & empty clip effects. Also note that I added the same effects with different audio for the M1911. The script below is my main code and mind you im getting an error for the handle under my variables where I define handle.

-- Variables

local tool = script.Parent.Parent
local hole = tool.barrel
local handle = tool.Handle
local canShoot = true
local config = tool.Config
local ammo = config.Ammo
local maxammo = config.MaxAmmo
local dmg = config.Damage
local allowtrace = config.AllowTracing
local clips = config.Clips
local range = config.Range
local plr = game:GetService("Players").LocalPlayer
local cooldown = config.CoolDown
local mouse = game.Players.LocalPlayer:GetMouse()
local reloadtime = config.ReloadTime
local isReloading = false
--//Sounds
local reload = tool.Handle.reloadAK
local fire = tool.Handle.akfire
local equip = tool.Handle.EquipSound
local empty = tool.Handle.emptyclip
local magin = tool.Handle.Magazinein


-- Events

tool.Equipped:Connect(function(mouse)
    equip:Play() -- Should play equip sound
    tool.Activated:Connect(function()
        if not isReloading then
            if ammo.Value > 0 then
        if canShoot then
            --Play Sound
            fire:Play() -- Should play Shooting Sound
            -- Doesnt Allow Spam
            canShoot = false
            -- Ray Get, & Set
            local ray = Ray.new(hole.CFrame.p, (mouse.hit.p - hole.CFrame.p) * range.Value)
            local hit, position = workspace:FindPartOnRay(ray, plr.Character, false, true)

            if allowtrace.Value == true then
                -- Make part
                local trace = Instance.new("Part", workspace)
                trace.Material = Enum.Material.Plastic
                trace.BrickColor = BrickColor.new("Really black")
                trace.CanCollide = false
                trace.Anchored = true
                trace.Locked = true
                trace.Transparency = 0.2

                -- Show Direction
                local distance = (hole.CFrame.p - position).magnitude
                trace.Size = Vector3.new(0.22, 0.1, distance)
                trace.CFrame = CFrame.new(hole.CFrame.p, position) * CFrame.new(0, 0, -distance/2)

                -- Remove Debris
                game:GetService("Debris"):AddItem(trace, 0.1)


            end
            -- Hit Detection
            if hit then
                local humanoid = hit.Parent:FindFirstChild("Humanoid")
                if humanoid then
                    -- Double Damage Headshots
                    if hit.Name == "Head" then
                        print("Headshot")
                        humanoid:TakeDamage(dmg.Value*2)
                    else
                        -- Regular Damage bodyshots
                        print("Bodyshot")
                        humanoid:TakeDamage(dmg.Value)
                    end
            end
            end
            ammo.Value = ammo.Value - 1
            wait(cooldown)
            canShoot = true
        end
            else
                -- out of ammo
                empty:Play()
        end
        end
    end)
    -- Reload event
    mouse.KeyDown:Connect(function(key)
        key:lower()
        if key == "r" then
            if not isReloading then
                if clips.Value > 0 then
                    reload:Play() -- Should Play Reload Sound
                    isReloading = true
                    ammo.Value = maxammo.Value
                    clips.Value = clips.Value - 1
                    wait(reloadtime.Value)
                    magin:Play() -- Should Play MagIn Sound
                    isReloading = false
                end
            end
        end
    end)
end)

Now ive gone through & placed notes where the sounds are called upon to play. Any other info to help me solve this I can also provide. Thanks for the help!

~GoodkidMad

0
Can I see the models? royaltoe 5144 — 2y
0
Maybe you are refrencing your tool wrong? Check if the tool is actually script.Parent.Parent royaltoe 5144 — 2y
0
Sure where should I send the links too GoodkidMad 14 — 2y
0
& No thats the first thing I checked. Trust me for me to be asking on here i've gone through the complete checklist of what could have been wrong. GoodkidMad 14 — 2y
View all comments (3 more)
0
Try using WaitForChild() or like referencing the thing handle from script.Parent.Parent.Handle itself maybe? Not the best coder here btw. RebornedInFire 35 — 2y
0
send a link here royaltoe 5144 — 2y
0
Sent on roblox to your messages the model GoodkidMad 14 — 2y

1 answer

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
2 years ago
Edited 2 years ago

The script was loading before the handle loaded, wait for the handle to load:

local handle = tool:WaitForChild("Handle")

0
I saw that you saw my message. Did you manage to fix it? royaltoe 5144 — 2y
0
Yes I just tried that & it fixed my issue. Man I literally was so lost for like a week & all because of a simple wait. The life of a programmer :p GoodkidMad 14 — 2y
0
Glad it fixed it. Can you please mark the solution I posted as answered so it's easier for people with similar problems to search for it? royaltoe 5144 — 2y
0
thx royaltoe 5144 — 2y
Ad

Answer this question