Homemade Bloxy Cola

Hello there!!! (- ^ ▽ ^ -)
I was bored so I just wanted to make another version for the Bloxy Cola.
image
This Bloxy Cola has a doodle of Builderman instead of the ROBLOXian itself, the text is written in Comic Sans and the top and bottom of it is cleaner. This is not just a retexture, it is also rewritten and it also has some simple animations instead of teleporting the soda can to the mouth. The only thing which is not remade is the mesh.

What can it do?


It can add 5 health to the player when they drink it (you can change that in the script) and has limited uses, but unlimited as default (you can also change that).

Link to the Model


Source Code


You can view the source code inside the script. If you want to view it in this post, here it is:

MainScript:

-- programmed by Giuyo4!!! :D
local tool = script.Parent
local tooltip = "It tastes different."
local handle = tool.Handle

local animations = {
	drink = {
		R6 = script.Parent.DrinkAnimation;
		R15 = script.Parent.DrinkAnimationR15;
	};
}

local health = 5 -- change this to the health you want to restore for the bloxy cola (set to 0 for none)
local sips = math.huge -- set math.huge for infinite, put a number if you want to make it limited.
local onCooldown = false

tool.ToolTip = tooltip

local function drink()
	local humanoid = tool.Parent:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
		if onCooldown == false then
			onCooldown = true

			local animator = Instance.new("Animator")
			animator.Name = "BloxyColaAnimator"
			animator.Parent = humanoid

			local drinkAnimationTrack
			if humanoid.RigType == Enum.HumanoidRigType.R6 then
				drinkAnimationTrack = animator:LoadAnimation(animations.drink.R6)
			elseif humanoid.RigType == Enum.HumanoidRigType.R15 then
				drinkAnimationTrack = animator:LoadAnimation(animations.drink.R15)
			end

			if sips > 0 then
				local animationTrack = animator:LoadAnimation(animations.drink.R6)
				animationTrack:Play()
				humanoid.Health = humanoid.Health + health
				sips = sips - 1
				tool.ToolTip=tooltip.." ("..tostring(sips)..")"
			end
			
			drinkAnimationTrack.Stopped:Wait()
			onCooldown = false
		end
	end
end

tool.Activated:Connect(drink)

onRunning

-- programmed by Giuyo4!!! :D
local tool = script.Parent

repeat
	task.wait(1)
until tool.Parent:FindFirstChildWhichIsA("Humanoid")

local humanoid = tool.Parent:FindFirstChildWhichIsA("Humanoid")

if humanoid then
	humanoid.Running:Connect(function(speed)
		if speed > 0 then
			script.Parent.MainScript.Disabled = true
		else
			script.Parent.MainScript.Disabled = false
		end
	end)
end

If you have found a bug, you can tell me or you can fix it yourself if you want to.

Note


This is my second post, so tell me if this should be in another category or there is something wrong.

Have a nice day! (- ^ v ^ -)

10 Likes

I like the idea! I see some things that could be changed such as just making a variable for the humanoid, and also storing the original walkspeed for said humanoid. But other than that pretty cool!

4 Likes

Thanks, I’ll try to make the WalkSpeed change to the original WalkSpeed other than ROBLOX’s default. (- ‘◡’ -)

Edit: I did it lol (- ^v^ -)

2 Likes

Another update, I’ve made the code more clean so you can read it.

2 Likes

Upgrade your bloxy cola tool script with enhanced features and Better performance! local tool = script.Parent
local drinkAnimationR6 = tool.DrinkAnimation
local drinkAnimationR15 = tool.DrinkAnimationR15
local amountOfHealthToGive = 5
local amountOfSips = -1

if amountOfSips >= 0 then
tool.ToolTip = “(”…amountOfSips…“)”
end

local isAnimating = false

local function playDrinkAnimation(humanoid, drinkAnimationTrack)
local originalWalkSpeed = humanoid.WalkSpeed
humanoid.WalkSpeed = 0
drinkAnimationTrack:Play()

isAnimating = true 

drinkAnimationTrack.Stopped:Wait()

humanoid.Health += amountOfHealthToGive
print("+"..amountOfHealthToGive.." health given to "..tool.Parent.Name)

humanoid.WalkSpeed = originalWalkSpeed
isAnimating = false

end

local function handleToolActivated()
if isAnimating then
print(“Animation is still playing. Please wait.”)
return
end

local humanoid = tool.Parent:FindFirstChildWhichIsA("Humanoid")
if not humanoid then
	warn("No existing humanoid found.")
	return
end

local animator = humanoid:FindFirstChildWhichIsA("Animator")
if not animator then
	animator = Instance.new("Animator")
	animator.Parent = humanoid
end

local drinkAnimationTrack
if humanoid.RigType == Enum.HumanoidRigType.R6 then
	drinkAnimationTrack = animator:LoadAnimation(drinkAnimationR6)
elseif humanoid.RigType == Enum.HumanoidRigType.R15 then
	drinkAnimationTrack = animator:LoadAnimation(drinkAnimationR15)
end

if amountOfSips == 0 then
	humanoid.WalkSpeed = 0
	warn("You ran out of Bloxy Cola.")
	tool.ToolTip = ""
	task.wait(1)
	humanoid.WalkSpeed = humanoid.WalkSpeed
elseif amountOfSips > 0 or amountOfSips < 0 then
	playDrinkAnimation(humanoid, drinkAnimationTrack)

	if amountOfSips > 0 then
		amountOfSips -= 1
		tool.ToolTip = "("..amountOfSips..")"
	end
end

end

tool.Activated:Connect(handleToolActivated)

2 Likes

ok I’ll do that later, thanks.

I feel like the script could REALLY use a clean-up, but other than that, this is cool.

1 Like

thanks for the feedback, also that has been said by the guy above my old post. ^v^

2 Likes

I make this code look a little bit better on the eyes lol.

Nonetheless, very cool!

-- programmed by @Giuyo4! :D

local tool = script.Parent
local drinkAnimation = tool.DrinkAnimation
local drinkAnimationR15 = tool.DrinkAnimationR15
local amountOfHealthToGive = 5 -- The health to give the player when the cola is interacted.
local amountOfSips = -1 -- Set to -1 or less for infinite.

if amountOfSips >= 0 then
    tool.ToolTip = "(" .. amountOfSips .. ")"
end

tool.Activated:Connect(function()
    local humanoid = tool.Parent:FindFirstChildWhichIsA("Humanoid")
    if humanoid then
        local originalWalkSpeed = humanoid.WalkSpeed
        local rigType = humanoid.RigType
        local animator = Instance.new("Animator")
        animator.Parent = humanoid

        local function handleDrink(drinkAnimationTrack)
            humanoid.WalkSpeed = 0
            drinkAnimationTrack:Play()
            humanoid.Health += amountOfHealthToGive
            print("+" .. amountOfHealthToGive .. " health given to " .. tool.Parent.Name)
            task.wait(1)
            humanoid.WalkSpeed = originalWalkSpeed
        end

        if rigType == Enum.HumanoidRigType.R6 then
            local drinkAnimationTrack = animator:LoadAnimation(drinkAnimation)

            if amountOfSips == 0 then
                humanoid.WalkSpeed = 0
                warn("You ran out of Bloxy Cola.")
                tool.ToolTip = ""
                task.wait(1)
                humanoid.WalkSpeed = originalWalkSpeed
            elseif amountOfSips >= 0 then
                handleDrink(drinkAnimationTrack)
                amountOfSips -= 1
                tool.ToolTip = "(" .. amountOfSips .. ")"
            elseif amountOfSips <= -1 then
                handleDrink(drinkAnimationTrack)
            end

        elseif rigType == Enum.HumanoidRigType.R15 then
            local drinkAnimationTrack = animator:LoadAnimation(drinkAnimationR15)

            if amountOfSips == 0 then
                humanoid.WalkSpeed = 0
                warn("You ran out of Bloxy Cola.")
                tool.ToolTip = ""
                task.wait(1)
                humanoid.WalkSpeed = originalWalkSpeed
            elseif amountOfSips >= 0 then
                handleDrink(drinkAnimationTrack)
                amountOfSips -= 1
                tool.ToolTip = "(" .. amountOfSips .. ")"
            elseif amountOfSips <= -1 then
                handleDrink(drinkAnimationTrack)
            end
        end
    else
        warn("No existing humanoid found.")
    end
end)
1 Like

Sorry for being late, I reworked the code.

1 Like

wait I forgot to publish the new update

hm wait let me add a cooldown for drinking
edit: done lol

1 Like

actually let me make the cooldown more accurate

1 Like

well I did a bit of the stuff you needed! =D

1 Like

What exactly are you talking about? What stuff specifically?

1 Like

Check the code again, I’m too lazy to explain what I did but I did a bit of your ideas in it.
Here the code:

-- programmed by Giuyo4!!! :D
local tool = script.Parent
local tooltip = "It tastes different."
local handle = tool.Handle

local animations = {
	drink = {
		R6 = script.Parent.DrinkAnimation;
		R15 = script.Parent.DrinkAnimationR15;
	};
}

local health = 5 -- change this to the health you want to restore for the bloxy cola (set to 0 for none)
local sips = math.huge -- set math.huge for infinite, put a number if you want to make it limited.
local onCooldown = false

tool.ToolTip = tooltip

local function drink()
	local humanoid = tool.Parent:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
		if onCooldown == false then
			onCooldown = true

			local animator = Instance.new("Animator")
			animator.Name = "BloxyColaAnimator"
			animator.Parent = humanoid

			local drinkAnimationTrack
			if humanoid.RigType == Enum.HumanoidRigType.R6 then
				drinkAnimationTrack = animator:LoadAnimation(animations.drink.R6)
			elseif humanoid.RigType == Enum.HumanoidRigType.R15 then
				drinkAnimationTrack = animator:LoadAnimation(animations.drink.R15)
			end

			if sips > 0 then
				local animationTrack = animator:LoadAnimation(animations.drink.R6)
				animationTrack:Play()
				humanoid.Health = humanoid.Health + health
				sips = sips - 1
				tool.ToolTip=tooltip.." ("..tostring(sips)..")"
			end
			
			drinkAnimationTrack.Stopped:Wait()
			onCooldown = false
		end
	end
end

tool.Activated:Connect(drink)