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
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
and isn`t this ( local tween = TweenService:Create(part, tweenInfo, {Color = greenColor})
) supposed to say local tween = TweenService:Create(part, tweenInfo, {Color3 = greenColor}) ?
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
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.