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

attempt to index number with 'Position'?

Asked by 4 years ago
Edited 4 years ago

I feel i am missing out on something and that im being dumb.

Can you fix this error? (On line 35) (Workspace.Crate Drops.Crate Drop.Handler:35: attempt to index number with 'Position')

DB = false
HitBox = script.Parent["Crate"].Hit
local Remote = script.Parent.Regen
local Workspace = game:GetService("Workspace")
HitBox.CFrame = CFrame.new(math.random(-1024,1024),1000,math.random(-1024,1024))
function Stuff(PRT)
        if not DB then
        local function SpawnItem(POS)
            if math.random(1,2) ~= 1 then
                Tier = 1
            else
                if math.random(1,4) ~= 1 then
                    Tier = 2
                else
                    if math.random(1,8) ~= 1 then
                        Tier = 3
                    else
                        if math.random(1,16) == 1 then
                            Tier = 4
                        else
                            Tier = 3
                        end
                    end
                end
            end
            local TierFolder = game.ServerStorage.Tools:FindFirstChild("Tier"..Tier)
            print(TierFolder)
            if TierFolder then
                local Tools = TierFolder:GetChildren()
                local RandomTool = Tools[math.random(1, #Tools)]
                if RandomTool then
                    local ToolClone = RandomTool:Clone()
                    ToolClone.Parent = script.Parent
                    if ToolClone.Parent == script.Parent and ToolClone and ToolClone:FindFirstChild("Handle") then
                        ToolClone.Handle.Position = POS.Position
                    end
                end
            end
        end
        local HUM = PRT.Parent:FindFirstChild("Humanoid")
        local PLR = game.Players:GetPlayerFromCharacter(PRT.Parent)
        if HUM and PLR then
            local LDR = PLR:FindFirstChild("leaderstats")
            local Points = LDR:WaitForChild("Points")
            local Multi = LDR:WaitForChild("Multiplier")
            local UMulti = LDR:WaitForChild("UL. Multiplier")
            if not HUM or not Points or not Multi or not UMulti then return end
            SpawnItem(1, script.Parent.Crate.Position1)
            local function DestroyWeld(Parent)
                for i, v in pairs(Parent:GetChildren()) do
                    if v:IsA("Weld") then
                        v:Destroy()
                    elseif v:IsA("Model") or v:IsA("Folder") or v:IsA("BasePart") then
                        DestroyWeld(v)
                    end
                end
            end
            DestroyWeld(HitBox.Parent)
            DB = true
            Multi.Value = UMulti.Value+1*Multi.Value + 0.1
            Points.Value = Points.Value + math.random(500,Multi.Value+1*3000)
            wait(30)
            HitBox.Parent.Parent = game.ServerStorage
            wait(math.random(30,60))
            Remote:Fire()
            Touched:Disconnect()
            HitBox = script.Parent["Crate"].Hit
            Touched = HitBox.Touched:Connect(Stuff)
            HitBox.Parent.Parent = script.Parent
            HitBox.CFrame = CFrame.new(math.random(-1024,1024),1000,math.random(-1024,1024))
            DB = false
        end
    end
end
Touched = HitBox.Touched:Connect(Stuff)

function IsInVoid()
    if HitBox.Position.Y >= -10 then return end
    HitBox.CFrame = CFrame.new(math.random(-1024,1024),1000,math.random(-1024,1024))
end

while wait(1) do
    IsInVoid()
end

Thank you, Btw the script is made for a crate supply thingy.

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

The problem is "POS" is equal to 1, as stated on line 48. Assuming there is nothing else wrong with the script, removing the "1" parameter should work. If you planing on using the first parameter, then add a second argument on line 8.

Edited version.


DB = false HitBox = script.Parent["Crate"].Hit local Remote = script.Parent.Regen local Workspace = game:GetService("Workspace") HitBox.CFrame = CFrame.new(math.random(-1024,1024),1000,math.random(-1024,1024)) function Stuff(PRT) if not DB then local function SpawnItem(POS) if math.random(1,2) ~= 1 then Tier = 1 else if math.random(1,4) ~= 1 then Tier = 2 else if math.random(1,8) ~= 1 then Tier = 3 else if math.random(1,16) == 1 then Tier = 4 else Tier = 3 end end end end local TierFolder = game.ServerStorage.Tools:FindFirstChild("Tier"..Tier) print(TierFolder) if TierFolder then local Tools = TierFolder:GetChildren() local RandomTool = Tools[math.random(1, #Tools)] if RandomTool then local ToolClone = RandomTool:Clone() ToolClone.Parent = script.Parent if ToolClone.Parent == script.Parent and ToolClone and ToolClone:FindFirstChild("Handle") then ToolClone.Handle.Position = POS.Position end end end end local HUM = PRT.Parent:FindFirstChild("Humanoid") local PLR = game.Players:GetPlayerFromCharacter(PRT.Parent) if HUM and PLR then local LDR = PLR:FindFirstChild("leaderstats") local Points = LDR:WaitForChild("Points") local Multi = LDR:WaitForChild("Multiplier") local UMulti = LDR:WaitForChild("UL. Multiplier") if not HUM or not Points or not Multi or not UMulti then return end SpawnItem(script.Parent.Crate.Position1) local function DestroyWeld(Parent) for i, v in pairs(Parent:GetChildren()) do if v:IsA("Weld") then v:Destroy() elseif v:IsA("Model") or v:IsA("Folder") or v:IsA("BasePart") then DestroyWeld(v) end end end DestroyWeld(HitBox.Parent) DB = true Multi.Value = UMulti.Value+1*Multi.Value + 0.1 Points.Value = Points.Value + math.random(500,Multi.Value+1*3000) wait(30) HitBox.Parent.Parent = game.ServerStorage wait(math.random(30,60)) Remote:Fire() Touched:Disconnect() HitBox = script.Parent["Crate"].Hit Touched = HitBox.Touched:Connect(Stuff) HitBox.Parent.Parent = script.Parent HitBox.CFrame = CFrame.new(math.random(-1024,1024),1000,math.random(-1024,1024)) DB = false end end end Touched = HitBox.Touched:Connect(Stuff) function IsInVoid() if HitBox.Position.Y >= -10 then return end HitBox.CFrame = CFrame.new(math.random(-1024,1024),1000,math.random(-1024,1024)) end while wait(1) do IsInVoid() end
0
Yes hasanchik 49 — 4y
Ad

Answer this question