Tween never plays for some reason?

so i’ve got a basic script that toggles the visibliity of the children of models, using CollectionService. but when i try to add tweening to make the game feel better to play, nothing happens?

this is what the prototype of my game looks like so far.

my script:

-- define the only constant
local VISIBLE_ENEMIES_TAG = "visible_enemies"

-- other variables + services
local collection_service = game:GetService("CollectionService")
local enemy_folder = workspace.map:FindFirstChild("enemies")
local run_service = game:GetService("RunService")
local tween_service = game:GetService("TweenService")
local debris = game:GetService("Debris")
local highlight = script.monstrous_highlight

local phone_info = TweenInfo.new(0.1, Enum.EasingStyle.Quint, Enum.EasingDirection.Out)

-- make enemies visible/invisible. true = visible, false = invisible
function set_enemy_visibility(enemy, visible)
	for _, child in ipairs(enemy:GetChildren()) do
		if child:IsA("BasePart") or child:IsA("MeshPart") or child:IsA("UnionOperation") then
			if child.Name ~= "HumanoidRootPart" then
				local target_transparency = visible and 0 or 1
				local current_transparency = child.Transparency

				local tween_goal = { Transparency = target_transparency }
				local tween = tween_service:Create(child, phone_info, tween_goal)
				tween:Play()
				print(child.ClassName)
			end
		end
	end
end

-- initialize the invisibility
for _, enemy in ipairs(enemy_folder:GetChildren()) do
	if collection_service:HasTag(enemy, "enemy") then
		set_enemy_visibility(enemy, false)
	else
		collection_service:AddTag(enemy, "enemy")
		set_enemy_visibility(enemy, false)
	end
end

-- may not be particularly efficient but will do for now
function on_instance_added(object)
	set_enemy_visibility(object, true)
end

function on_instance_removed(object)
	set_enemy_visibility(object, false)
end

-- handle when enemies can or can not be seen by the player's phone
collection_service:GetInstanceAddedSignal(VISIBLE_ENEMIES_TAG):Connect(on_instance_added)
collection_service:GetInstanceRemovedSignal(VISIBLE_ENEMIES_TAG):Connect(on_instance_removed)

-- also detect any npcs that may already have the tag
for _, object in pairs(collection_service:GetTagged(VISIBLE_ENEMIES_TAG)) do
	on_instance_added(object)
end

It seems to be working on the video, you just have the speed so fast. Set the Tween speed to 1 to like test it at first.

1 Like

It could be because you have visible, when tweening transparency your not making it visible only modifing the value of transparency which can only be between 0-1. Just replace the whole = to 1 and add an if statement:

local target_transparency
if target_transparency == 1 then
	target_transparency = 1
else
	target_transparency = 0
end

this might not be the best solution but I would try it, and try what @Laqotaa said by increasing the speed. (edit: im not the most knowledgable when using the visible and 0 or 1 so it may not be for the reason i said)

2 Likes

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