TweenService issue

I have an issue regarding why the tween doesn’t work. The script is supposed to change the stage checkpoint so green whenever it is touched, everything prints out (hit, 1, 2, 3, 4) but it does not change the stage part itself… and i can’t find the issue.

local stages = game.Workspace.Stages:GetChildren()
local TweenService = game:GetService("TweenService")

local lastTouchTimes = {}  
local debounceTime = 3    

local function applyTween(part)
	print("1")
	local originalColor = part.BrickColor
	local greenColor = BrickColor.new(Color3.fromRGB(0, 255, 0))

	local tweenInfo = TweenInfo.new(
		1,
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.Out,
		0                       
	)
	print("2")
	local tween = TweenService:Create(part, tweenInfo, {Color = greenColor.Color})
	tween:Play()
	print("3")
	
	tween.Completed:Connect(function()
		part.BrickColor = originalColor
		print("4")
	end)
end

for _, stage in ipairs(stages) do
	stage.Touched:Connect(function(hit)
		if hit:IsA("BasePart") then
			local currentTime = tick()
			local lastTouchTime = lastTouchTimes[hit]

			if not lastTouchTime or currentTime - lastTouchTime >= debounceTime then
				lastTouchTimes[hit] = currentTime
				print("hit")
				applyTween(hit)
				wait(debounceTime) 
			end
		end
	end)
end
1 Like

BrickColor is different from Color3. Either change greenColor to a Color3 value or rename the Color key in the properties table to BrickColor.

I have changed the variable greenColor to “local greenColor = Color3.fromRGB(0,255,0)” and the function still won’t change the color…

The new script if needed:

local players = game:GetService("Players")
local leaderstats = players.LocalPlayer:WaitForChild("leaderstats")
local value = leaderstats:WaitForChild("Stage")

local stages = game.Workspace.Stages:GetChildren()
local TweenService = game:GetService("TweenService")

local lastTouchTimes = {}  
local debounceTime = 3    

local function applyTween(part)
	print("1")
	local originalColor = part.BrickColor
	local greenColor = Color3.fromRGB(0,255,0)

	local tweenInfo = TweenInfo.new(
		1,
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.Out,
		0                       
	)
	print("2")
	local tween = TweenService:Create(part, tweenInfo, {Color = greenColor})
	tween:Play()
	print("3")
	
	tween.Completed:Connect(function()
		part.BrickColor = originalColor
		print("4")
	end)
end

for _, stage in ipairs(stages) do
	stage.Touched:Connect(function(hit)
		if hit:IsA("BasePart") then
			local currentTime = tick()
			local lastTouchTime = lastTouchTimes[hit]

			if not lastTouchTime or currentTime - lastTouchTime >= debounceTime then
				lastTouchTimes[hit] = currentTime
				print("hit")
				applyTween(hit)
				wait(debounceTime) 
			end
		end
	end)
end

could you show us the error or if there isn`t an error try removing the “local” of the function applyTween(part)
[Im not an expert]

  • Is the part already green?
  • How long does it take for tween.Completed to be called?
  • Have you tried removing the 4th argument of tweenInfo? I’m very familiar but I’ve never had to use a fourth argument.

and isn`t this ( local tween = TweenService:Create(part, tweenInfo, {Color = greenColor})
) supposed to say local tween = TweenService:Create(part, tweenInfo, {Color3 = greenColor}) ?

The correct property is Color, not Color3
Color3 is the data type that BasePart.Color accepts.

All the parts are white, the prints from 1 -3 gets called instantly, and the 4th print gets called roughly 1,5-2 seconds after the others. And removing the 4th argument does not do anything unfortunately… and no errors show in the output

Would you be willing to add me to Team Create temporarily so I can address the issue directly?

Wait, I’ve found it. You’re tweening hit, not stage. In other words, you’re tweening the colour of the character’s legs instead of the stage itself. You don’t see a change because your character is presumably wearing pants.

Fix

Change applyTween(hit) to applyTween(stage).

You are a genius haha, i did look at the parameter and wonder why it had hit in it but didnt do anything… it works now, thanks

1 Like

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