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

Can't seem to get custom made parts to clone after tool hits an object?

Asked by 3 years ago
Edited 3 years ago

So what I have been trying to do with this is to make a fossil hunter kind of game into a kind of simulator. I have asked a similar question like this before, and some of the errors have been fixed up, like the whole eof situation and the problem with CloneObject.CFrame, but more errors keep on popping up, and I am not sure if I even have the code written right at this point. As of now, the mineType, which I am using to do a random number generator to randomly get an ore, seems to be broken. What it is supposed to do is choose a random number for spawning, or in this case, cloning parts that are in the workspace (In this case, Unknown Rock, Arm/Leg Fossil, Rib Fossil, Tail Fossil, and Skull Fossil). I am not sure on what to do at this point, and I am starting to think I may have to rewrite it in an entirely new way, which is a bit worrying since I am still new at this whole Lua scripting.The script is for a pickaxe that I made when it hits an object called Fossil Chunk.

local tool = script.Parent
local canMine = false

local function onTouch (otherPart)
    if otherPart.name == 'Fossil Chunk' and canMine then
        canMine = false
        local minedPart = Instance.new('Part')
        minedPart.Parent = game.Workspace
        minedPart.Size = Vector3.new(2,1,2)
        minedPart.Position = otherPart.Position + Vector3.new(math.random(-5,5), 5, math.random(-5,5))
        local mineType = math.random(1,100)
        if mineType < 30 then
            local Object = game.ReplicatedStorage:WaitForChild("Unknown Rock")
            local ObjectSpawn = game.Workspace:WaitForChild("Fossil Chunk")
                local CloneObject = Object:Clone()
                CloneObject.Parent = game.Workspace
                CloneObject.CFrame = CloneObject.CFrame
            end
        end
        if mineType > 30 and mineType < 50 then
            local Object = game.ReplicatedStorage:WaitForChild("Arm/Leg Fossil")
            local ObjectSpawn = game.Workspace:WaitForChild("Fossil Chunk")
                local CloneObject = Object:Clone("Arm/Leg Fossil")
                CloneObject.Parent = game.Workspace
                CloneObject.CFrame = CloneObject.CFrame
            end
        end
        if mineType > 50 and mineType < 70 then
            local Object = game.ReplicatedStorage:WaitForChild("Rib Fossil")
            local ObjectSpawn = game.Workspace:WaitForChild("Fossil Chunk")
                local CloneObject = Object:Clone("Rib Fossil")
                CloneObject.Parent = game.Workspace
                CloneObject.CFrame = CloneObject.CFrame
            end

        if mineType > 70 and mineType < 85 then
            local Object = game.ReplicatedStorage:WaitForChild("Tail Fossil")
            local ObjectSpawn = game.Workspace:WaitForChild("Fossil Chunk")
                local CloneObject = Object:Clone("Tail Fossil")
                CloneObject.Parent = game.Workspace
                CloneObject.CFrame = CloneObject.CFrame
            end

        if mineType > 85 then
            local Object = game.ReplicatedStorage:WaitForChild("Skull Fossil")
            local ObjectSpawn = game.Workspace:WaitForChild("Fossil Chunk")
                local CloneObject = Object:Clone("Skull Fossil")
                CloneObject.Parent = game.Workspace
                CloneObject.CFrame = CloneObject.CFrame
            end



local function slash()
    local str = Instance.new("StringValue")
    str.Name = "toolanim"
    str.Value = "Slash"
    str.Parent = tool
    canMine = true
end

tool.Activated:Connect (slash)
tool.Handle.Touched:Connect (onTouch)

I am mainly a model creator, not so much a scripter, so the scripting section is new to me still.

Answer this question