Hello DevForum! I’m currently having an issue with using “For i, v” loops for tweening, specifically fading things in, but it seems like the script I’ve made doesn’t work.
The script:
local TS = game:GetService("TweenService")
local Player = game:GetService("Players").PlayerAdded:Wait()
local TpGui = Player.PlayerGui:WaitForChild("TpToHell")
local TpFrame = TpGui:WaitForChild("Frame")
local TpHolder = TpFrame:WaitForChild("Holder")
local info = TweenInfo.new(5)
script.Parent.Touched:Connect(function(object)
if object.Parent:FindFirstChild("Humanoid") then
local hum = object.Parent:WaitForChild("Humanoid")
Player = game:GetService("Players"):GetPlayerFromCharacter(object.Parent)
for i, v in pairs(TpHolder:GetDescendants()) do
if v:IsA("Frame") then
TS:Create(v, info, {BackgroundTransparency = 0}):Play()
elseif v:IsA("TextLabel") then
TS:Create(v, info, {TextTransparency = 0}):Play()
TS:Create(v, info, {BackgroundTransparency = 0.9}):Play()
elseif v:IsA("UIStroke") then
TS:Create(v, info, {Transparency = 0}):Play()
end
TS:Create(TpHolder, info, {BackgroundTransparency = 0}):Play()
end
end
end)
Can anyone tell me why it’s not working and what i could do to get it to work? Thanks!
(beware that i am new to using For i loops so don’t be surprised if i made some dumb mistake)
That won’t make a noticeable difference; they will both work as iterators within the loop.
pairs is used for dictionaries that have string keys, and ipairs is used for tables that have number keys. Using pairs on a number table does not cause an issue, but using ipairs on a dictionary would cause an issue. ipairs would be ~0.01 seconds speed difference to pairs, but next is about the same speed as them to I just tend to use next as an iterator.
That’s only going to tween for one player. I would recommend doing all the gui stuff on the client, and then you could fire a remote to the client telling them to tween the gui.
then use a remote like I suggested and a LocalScript inside the gui. Doing gui on the server is bad practice anyway. It’s much easier and doesn’t eat into server memory.
local players = game:GetService("Players")
local rStorage = game:GetService("ReplicatedStorage")
local part = pathToPartHere
local remote = pathToRemoteHere
local player = players:FindFirstChildOfClass("Player") or players.PlayerAdded:Wait()
local function onTouch(hit:BasePart)
local char = hit:FindFirstAncestorOfClass("Model")
if char and players:GetPlayerFromCharacter(char) then
remote:FireClient(player)
end
end
part.Touched:Connect(onTouch)