Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

CFrame and for i,v script isn't working. A little help?

I'm trying to recreate a scene of podiums moving upwards here, but it isn't working. I think it's because of :GetPrimaryPartCFrame because the output says 14:53:33.796 - Workspace.scrum debate.SurfaceGui.Frame.TextButton.Script:6: attempt to call method 'GetPrimaryPartCFrame' (a nil value) but I don't know how to fix it. A little help?

EDIT: Since I wanted it in order, the I removed game.Workspace.podiums:GetChildren() and changed it to the actual children. This is because it won't going to not make the podiums move in order if I use :GetChildren(). If anyone knows how to help me to make this more efficient, then thank you. Also, I edited it based on the first answer.

local podiums = game.Workspace.podiums
local podiumtable = {podiums.podium1,
podiums.podium2,
podiums.podium3,
podiums.podium4,
podiums.podium5,
podiums.podium6,
podiums.podium7,
podiums.podium8,
podiums.podium9,
podiums.podium10,
podiums.podium11,
podiums.podium12,
podiums.podium13,
podiums.podium14,
podiums.podium15,
podiums.podium16,
}

script.Parent.MouseButton1Click:Connect(function()
	  for i,v in pairs(podiumtable) do
	       for i = 0.5,1,.005 do
	       v:SetPrimaryPartCFrame(v:GetPrimaryPartCFrame()* CFrame.new(0,i,0))
	       wait()
			
	       end
	   end
end)

2 comments

0

Accept my answer if works :)

0

Edited answer

1 answer

✓ Accepted answer

You're attempting to call a method in the podiums array that doesn't exist. I believe you meant to get the CFrame of v

local podiums = game.Workspace.podiums:GetChildren()

script.Parent.MouseButton1Click:Connect(function()
    for i,v in pairs(podiums) do
        for i = 0,1,.001 do
        v:SetPrimaryPartCFrame(v:GetPrimaryPartCFrame()* CFrame.new(0,i,0))
        wait()
        end
    end
end)

#Edit You can use TweenService to animate the model going from one point to another.

local TweenService = game:GetService("TweenService")
local info = TweenInfo.new() -- # default tween info
local podiumsObject = game.Workspace.podiums
local podiumsTbl = {}
local properties = {
    ["CFrame"] = CFrame.new(0, 1, 0)

for i, v in ipairs(podiumsObject:GetChildren()) do
    table.insert(podiumsTbl, podiumsObject["podium" .. i])
end

for _, podium in ipairs(podiumsTbl) do
    local tween = TweenService:Create(
        podium.PrimaryPart, -- # instance to tween
        info, -- # tween info
        properties -- # properties dictionary 
    ) -- # create tween object for individual podiums
    tween:Play()
    tween.Completed:Wait() -- # wait for individual tween to complete 
end

info is just a default TweenInfo. Studios intellisense autocomplete should show the order of the arguments to pass so you can fiddle with those until you find a good fit.

What I do then is iterate over the children of podiums and insert them into podiumsTbl. podiumsObject["podium .. i"] is there to guarantee order from podium 1, podium2, etc. when iterating over podiumsTbl. properties is a dictionary whose keys will be the properties to tween and the values to tween to. So in this case it would tween the CFrame property to CFrame.new(0, 1, 0).

Also, as a side note, the proper terminology for "for i, v" is a generic for loop.

1 comment

0

The podiums move upward, which means your script worked, but each podium goes up after one podium is already finished going up. I need it so that like, when one starts moving, another starts moving, and another starts moving etc etc. Not exactly when one is finished moving, one starts moving. I also edited my question sadjslaj

This discussion is preserved as it was. New answers, comments, and votes are closed.