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

Whats wrong with my Instance.new? Still need help!

Asked by
Dr_Doge 100
9 years ago

So im makeing a Save Bricks Script, and I have the Save Button down, but I need help on the load button...

When a player saves, a Value is created inside there game.Players called Save

Inside Save there are multiple Values Called Part In part, theres a Value called pos and in pos there are 3 values called X , Y, and Z.

There are other things inside part, like the rotation and size but thats not important right now...

Link to the game im working on: http://www.roblox.com/games/272707007/Infinity

local Gui = script.Parent
local Player = Gui.Parent.Parent.Parent
local Char = Player.Character
local save = Player:FindFirstChild("Save")
local part = save:FindFirstChild("Part")

function onClicked()
if save ~= nil then
    while true do
        if part ~= nil then
            local loadpart = Instance.new("Part",game.Workspace)
            loadpart.Anchored = true
            loadpart.CFrame = CFrame.new(Vector3.new(part.pos.X,part.pos.Y,part.pos.Z))
        end
    end
end
Gui.MouseButton1Click:connect(onClicked)



Thank you for reading!

1 answer

Log in to vote
0
Answered by 9 years ago

Next time, try to be more specific about what is going wrong. I have looked over your code and your while loop seems to be cause you some problems. First of all, there is no way for the script to get out of the loop, meaning it will sit there trying to spawn parts even if they have all been spawned. Also, there must be a wait inside your while loop otherwise it will crash. Another thing is that local part = save:FindFirstChild("Part") isn't going to work as it will only find one part, and only spawn that 1 part.

What you have isn't very well written code, so I suggest you use something along the lines of :

function onClicked()
    if save then
    for i,v in pairs(save:GetChildren()) do
         local loadpart = Instance.new("Part",game.Workspace)
             loadpart.Anchored = true
             loadpart.CFrame = CFrame.new(Vector3.new(v.pos.X,v.pos.Y,v.pos.Z))
    end
    end
end

0
o Thanks for trying, but this did't work... also the :FindFirstChild was going to work. I was planing on Removing the value once the script was done with it... Also i apologize on being slopy and not being specific enough, but I tried to be as specific as possible... Im Self taught so I dont know everything and thats one of the reasons im slopy... Thank you for taking your time and helping me! Dr_Doge 100 — 9y
Ad

Answer this question