Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make a mined object drop custom parts?

I am making a kind of paleontology game that requires you to mine up chunks of fossil. I learned via a video and was able to get it to work, but when I tried to set it up to use custom parts that I made for this piece, the whole tool would not work. This is the script that I have set up at the moment. The less than 30 section is what I was working on at the moment, and the rest is still the original section.

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("ObjectName")
			local ObjectSpawn = game.Workspace:WaitForChild("ObjectSpawn") 
 				local CloneObject = Object:Clone() 
   				CloneObject.Parent = game.Workspace
				CloneObject.CFrame.p
			end
		end
		if mineType > 30 and mineType < 50 then
			minedPart.BrickColor = BrickColor.new('Black')
		end
		if mineType > 50 and mineType < 70 then
			minedPart.BrickColor = BrickColor.new('Gold')
		end
		if mineType > 70 and mineType < 85 then
			minedPart.BrickColor = BrickColor.new('Teal')
		end
		if mineType > 85 then
			minedPart.BrickColor = BrickColor.new('Dark green')
		end
	end
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 not sure on how to fix this, and the errors pop up on CloneObject.CFrame.p stating that it is an incomplete statement and it expected an assignment or function call. I am still a beginner at scripting for Roblox, so I am next to clueless on how to fix this.

1 answer

You made a simple mistake, so what that incomplete statement means is you was calling The CFrame and then doing nothing with it, leaving it as an incomplete statement, a way to fix this is by removing that line as it looks useless or making it work by finishing the line.

If you wanted to remove it you could just do this;

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("ObjectName")
            local ObjectSpawn = game.Workspace:WaitForChild("ObjectSpawn") 
            local CloneObject = Object:Clone() 
            CloneObject.Parent = game.Workspace
        end
        if mineType > 30 and mineType < 50 then
            minedPart.BrickColor = BrickColor.new('Black')
        end
        if mineType > 50 and mineType < 70 then
            minedPart.BrickColor = BrickColor.new('Gold')
        end
        if mineType > 70 and mineType < 85 then
            minedPart.BrickColor = BrickColor.new('Teal')
        end
        if mineType > 85 then
            minedPart.BrickColor = BrickColor.new('Dark green')
        end
    end
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)

Or to fix it(Maybe idk what you're using so this may fix it, if not try using Position instead)

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("ObjectName")
            local ObjectSpawn = game.Workspace:WaitForChild("ObjectSpawn") 
            local CloneObject = Object:Clone() 
            CloneObject.Parent = game.Workspace
            CloneObject.CFrame = ObjectSpawn.CFrame
        end
        if mineType > 30 and mineType < 50 then
            minedPart.BrickColor = BrickColor.new('Black')
        end
        if mineType > 50 and mineType < 70 then
            minedPart.BrickColor = BrickColor.new('Gold')
        end
        if mineType > 70 and mineType < 85 then
            minedPart.BrickColor = BrickColor.new('Teal')
        end
        if mineType > 85 then
            minedPart.BrickColor = BrickColor.new('Dark green')
        end
    end
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)

Hope this helps, or fixes your issue

EDIT: Fixed a error with end placements, should work now

2 comments

0

It seems that a new error appeared after fixing the last error. This error says at line 33, it expected , but got end. I am not quite sure on how to get that in, since when I type either end of file, end of function, or simply eot, it pops up as an error saying that this is an incomplete statement.

0

Alright, one moment i see whats wrong

This discussion is preserved as it was. New answers, comments, and votes are closed.