Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why the tween still triggers if i did not touch it?

Asked by 1 year ago
Edited 1 year ago

So i have this unusual incident today, i made a sphere with a tween that must become 0.5 transparent, 16,16,16 sized, cannot be collided with, and in order to activate it, a player with a humanoid must touch it

But, even when i moved it from the baseplate, it still continued to tween without the permission

The output reports no exceptions tho

local TweenService = game:GetService("TweenService")

local sphere = script.Parent

local goal = {}
sphere.Transparency = 0.5
sphere.Size = Vector3.new(16, 16, 16)
sphere.Color = Color3.new(0.203922, 0.8, 0.854902)
sphere.CanCollide = false

local info = TweenInfo.new(
    3,
    Enum.EasingStyle.Cubic,
    Enum.EasingDirection.Out,
    0,
    true,
    1

)

local sphereTween = TweenService:Create(sphere, info, goal)

sphere.Touched:Connect(function(otherPart)
    local humanoid = otherPart.Parent:FindFirstChildWhichIsA("Humanoid")
    if humanoid then
        sphereTween:Play()
    end
end)

1 answer

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

It's better to be using if humanoid ~= nil then so it checks if the object contains humanoid or not. It's a better way to check for humanoid.

Also, if you want to tween the transparency and stuff, put that inside the table.

Make sure that there is no colliding humanoids, if you want this to work only for the player, use game.Players:GetPlayerFromCharacter(otherPart.Parent) so it would look like this:

local TweenService = game:GetService("TweenService")

local sphere = script.Parent

local goal = {
    Transparency = 0.5,
    Size = Vector3.new(16, 16, 16),
    Color = Color3.new(0.203922, 0.8, 0.854902),
    -- Since CanCollide can't be tweened, you can still put it here
    CanCollide = false
}

local info = TweenInfo.new(
    3,
    Enum.EasingStyle.Cubic,
    Enum.EasingDirection.Out,
    0,
    true,
    1
)

local sphereTween = TweenService:Create(sphere, info, goal)

sphere.Touched:Connect(function(otherPart)
    local humanoid = otherPart.Parent:FindFirstChildWhichIsA("Humanoid")
    if humanoid ~= nil and game.Players:GetPlayerFromCharacter(otherPart.Parent) then
        sphereTween:Play()
    end
end)

0
Didnt work Artemiygogolev 23 — 1y
0
I even tried doing this in a new baseplate, it still tweened, maybe its sort of a studio bug? Whats your opinion? Artemiygogolev 23 — 1y
0
I edited the script: you are setting the sphere's properties before player touches the tween so I made the working script now GamerLighting23233 63 — 1y
0
oh my god it worked, i didnt really understand the reason of the problem, we are obliged to set needed properties before executing tween,im sorry if im asking too much but i really need to know my every mistake Artemiygogolev 23 — 1y
Ad

Answer this question