The ball takes a long time to get small

  1. What do you want to achieve?

making the balls get smaller when the player touches them.

  1. What is the issue? Include screenshots / videos if possible!

When the player plays them at a normal speed, they work fine, but when the player plays them at a very slow speed, it doesn’t work as it should.

  1. What solutions have you tried so far??

Place a variable so that the touch would not be executed so many times but it did not work

This is the ball code.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Module = require(ReplicatedStorage.Modules.SnowMoneyModule)
local BallTouchedSound = game.StarterPlayer.StarterPlayerScripts.Sounds.SnowBall

local SnowBall = script.Parent
local OriginalPosition = SnowBall.Position
local OriginalSize = SnowBall.Size

local SoundActivated = false
local debounce = false


local function SmallBall()
	for i = 1,100 do
		wait(0.00001)
		SnowBall.Size = SnowBall.Size - Vector3.new(0.1,0.1,0.1)
		SnowBall.Position = SnowBall.Position + Vector3.new(0,0.2,0)
	end	
end



SnowBall.Touched:Connect(function(hit)
	
	local Humanoid = hit.Parent:FindFirstChild("Humanoid")
	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	
	if Humanoid and Player then
		debounce = true
		if SoundActivated == false then
			SoundActivated = true
			BallTouchedSound:Play()
			wait(1)
			SoundActivated = false
		end
		SmallBall()
--		wait(5)
--		SnowBall.Position = OriginalPosition
--		SnowBall.Size = OriginalSize
	 end
end)

it seems like you could tween this instead, heres the service and a video on it:

side note: that func would yield the whole script (i think) unless coroutined/task.spawned

1 Like

Brother your debounce isn’t doing anything in the portion of code you’ve given. It’s supposed to act as a condition to prevent the execution of code until the code encapsulated has been completed, essentially a cooldown.

local debounce = false
local function dosmth()
    if debounce == false then
        debounce = true
        -- do stuff
        debounce = false -- now you can do stuff again
    end
end

Furthermore, wait() has a minimum duration of 0.05 seconds and is deprecated. task.wait() does not throttle.

As @functionally_wicked mentioned, use the TweenService if you plan to gradually change the size of your object. It’s better practice.

2 Likes

thanks for bringing this up, i forgot to, wait() is such a bad practice.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.