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

How do you make the torso of a character explode when it reaches a certain size?

Im trying to make a script where lets say if the torso of a player reaches a certain size, i.e. 10, then the torso explodes.

if Torso.Size >= Torso.Size + Vector3.new(10,10,10) then
	local explosion = Instance.new("Explosion",Torso)
end

Torso.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if touchingTorso == false then
		print(hit.Parent)
		if hit.Parent:FindFirstChild("Torso") then
			print(hit.Parent:FindFirstChild("Torso"))
				Torso.Size = Torso.Size + Vector3.new(.1,.1,.1)
				touchingTorso = true
			end
		end
	end
end)

Torso.TouchEnded:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if touchingTorso == true then
			if hit.Parent:FindFirstChild("Torso") then
				touchingTorso = false
			end
		end
	end	
end)

this is all i have and all of my attempts of doing this on my own have failed, can anyone help me?

2 answers

✓ Accepted answer

You cannot use if statements to constantly check if something has been changed. In your example, it's only running once. You'll need to put this in the event.

Additionally, you cannot compare Vector3s directly. You'll have to check against some starting value, for example, if the Torso's size grows 3x bigger than what it was.

local maxSize = Torso.Size*3 -- This means that our "maximum size" is 3x the size of the Torso.

function isBiggerThan(v3_1, v3_2)
    -- This compares each axis. We're going to compare the torso's size against it.
    return v3_1.X > v3_2.X and v3_1.Y > v3_2.Y and v3_1.Z > v3_2.Z
end

Torso.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        if touchingTorso == false then
        print(hit.Parent)
        if hit.Parent:FindFirstChild("Torso") then
            print(hit.Parent:FindFirstChild("Torso"))
                Torso.Size = Torso.Size + Vector3.new(.1,.1,.1)
                touchingTorso = true

                -- Now we need to check the Torso's *current* size. Is it bigger than our maxSize?
                if isBiggerThan(Torso.Size, maxSize) then
                    local explosion = Instance.new("Explosion")
                    explosion.Position = Torso.Position
                    explosion.Parent = workspace
                    touchingTorso = false
                    -- Explosion position needs to be set for it to blow up the torso.
                end
            end
        end
    end
end)

Torso.TouchEnded:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        if touchingTorso == true then
            if hit.Parent:FindFirstChild("Torso") then
                touchingTorso = false
            end
        end
    end 
end)

1 comment

0

Thanks this genuinly helped alot!

if Torso.Size == 10 then
	local explosion = Instance.new("Explosion")  -- Adding the explosion into the torso
	explosion.Parent = Torso -- I'm not sure where you put the script so just replace Torso with something you have 
	wait(0.5)
	Torso:Destroy()  -- remove the torso
else
	wait()
end

Something like this, I think your script is missing the

local touching Torso = false 

on top. On line 1, is

Torso = script.Parent  -- ? 	

You should also use

for i, v =  1, 0 do  --  the amount of time you want the thing to run
	Torso.Size = Torso.Size + Vector3.new(.1,.1,.1)
	wait()  -- time waiting
end

You should also add a debounce to your script in case it is going midway and it restarts. Can you also explain to me more about where you place your script and more of what you are planning to do i.e When a player touch a block, their torso gets bigger until they explode. Hope this help and also ask me anything else you want.

1 comment

0

Tried to implement this into my script, didnt work sadly sorry

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