Why does this not work, can someone tell me what I am doing wrong?
for i, v in next, workspace:GetDescendants() do
if v:IsA("SpawnLocation") then
local newpos = v.CFrame * Vector3.new(0,v.Size.Y/2+30,0)
end
end
local TweenService = game:GetService("TweenService")
local part = game.Players.LocalPlayer.Character.HumanoidRootPart -- Change to the part you want to tween
part.Anchored = true
local info = TweenInfo.new(
5, -- Time it will take
Enum.EasingStyle.Sine, -- Easing style
Enum.EasingDirection.InOut, -- Easing direction
0, -- Repeat count
false, -- Reverses
0 -- Delay
)
local goals = {CFrame = newpos}
local tween = TweenService:Create(part, info, goals)
tween:Play()
wait(5)
part.Anchored = false
Idk what you’re exactly doing with this, but if this is a Scriptthere is no way to obtain the LocalPlayer
If it’s a LocalScript, I’d recommend waiting for the Character’s HumanoidRootPart to properly load in time cause there might be a chance that it may not work & result back an error:
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
You’re trying to reset the variable for every SpawnLocation there is in the entire workspace, unless if you have like some sort of table you can loop through it’ll only just Tween the most recent newpos variable to that CFrame
local Positions = {}
for _, Object in pairs(workspace:GetDescendants()) do
if Object:IsA("SpawnLocation") then
table.insert(Positions, Object.CFrame * Vector3.new(0, Object.Size.Y / 2 + 30), 0)
end
end
Honestly I am confused about what the intended behavior should be. Although if the goal is to tween the player to every spawn one by one this should probably work:
--LocalScript/Script inside StarterCharacterScripts
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local Character = script.Parent
function tween(newpos)
local part = Character.HumanoidRootPart
part.Anchored = true
local info = TweenInfo.new(
5, -- Time it will take
Enum.EasingStyle.Sine, -- Easing style
Enum.EasingDirection.InOut, -- Easing direction
0, -- Repeat count
false, -- Reverses
0 -- Delay
)
local goals = {CFrame = newpos}
local tween = TweenService:Create(part, info, goals)
tween:Play()
task.wait(5)
part.Anchored = false
end
--use pairs when looping through objects
for i, v in pairs(workspace:GetDescendants()) do
if v:IsA("SpawnLocation") then
--you can't multiply vectors with CFrames!, instead make the vector a CFrame
local pos = Vector3.new(0,v.Size.Y/2+30,0)
local newpos = v.CFrame * CFrame.new(pos)
--the tween code should be run inside the loop, else it will break
tween(newpos)
end
end