local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local plr = Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:wait()
local btn = script.Parent
local function CharacterAdded()
local goal = {}
goal.Position = UDim2.fromScale(0.5,0.682)
local tweenInfo = TweenInfo.new(3,Enum.EasingStyle.Bounce)
local tween = TweenService:Create(btn, tweenInfo, goal)
tween:Play()
end
local function PlayerAdded()
if char then
CharacterAdded()
end
end
Players.PlayerAdded:Connect(PlayerAdded())
This one below doesn’t work; it doesn’t error, the function just doesn’t get triggered for whatever reason.
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local plr = Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:wait()
local btn = script.Parent
Players.PlayerAdded:Connect(function()
if char then
local goal = {}
goal.Position = UDim2.fromScale(0.5,0.682)
local tweenInfo = TweenInfo.new(3,Enum.EasingStyle.Bounce)
local tween = TweenService:Create(btn, tweenInfo, goal)
tween:Play()
end
end)
I’m not really sure why this could be. Does anyone have any idea?
It still isn’t working. The problem isn’t the Tweening itself, it’s that the function will not fire when it’s being defined while also connecting to the event. (The second code I posted)
The tweening works fine in the first code.
Yeah this doesn’t work either. I don’t want to rewrite the code completely, I’m only just confused why one works but the other doesn’t when they’re both doing the same thing just in a different syntax.
Use prints to make sure the if char then is actually true.
Instead of creating the property table this way:
Try this way:
local goal = { Position = UDim2.fromScale(0.5,0.682) }
To be safe, define all of the arguments in TweenInfo.new()
You should do plr.CharacterAdded:Wait(), make the wait() uppercase.
And also, I see this common mistake with beginner developers. When using :Connect(), You don’t use the parentheses. You just REFERENCE the function. Don’t call it. Example:
Players.PlayerAdded:Connect(PlayerAdded) -- good
Players.PlayerAdded:Connect(PlayerAdded()) -- bad, this won't work.
Again, it’s bad practice to name a function the same as an event.
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local plr = Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local btn = script.Parent
Players.PlayerAdded:Connect(function()
if char then
local goal = { Position = UDim2.fromScale(0.5,0.682) }
local tweenInfo = TweenInfo.new(3,Enum.EasingStyle.Bounce,Enum.EasingDirection.Out)
local tween = TweenService:Create(btn, tweenInfo, goal)
tween:Play()
end
end)
Also like you said, I think the reason the first code was “working” was because it was calling the function when it was supposed to be “connecting” to the event. But now that I fixed it and removed the parenthesis, I can see the entire event is not connecting to the function.
I included prints right above the if statement at the beginning of the function, and one inside the if statement and got nothing in the output.