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

Please forgive me, I have no idea how to word this, I need help with a script?

Asked by 8 years ago

Hi, thanks for clicking on my question :) I really appreciate it.

I'm trying to make a GUI where you click a button (I already got that down) and it clones a Box from game.Lighting and puts it in the Player's character. I want the button to remove an already existing Box that the Player owns and spawn a new one right in front of the Player.

It's my weird way of trying to script because I don't remember half of the stuff I used to know how to do, LOL.

Can someone write me a new script or revise the one I have now for it to do what I want it to?

Here's what I have so far:

function onButtonClicked()

        if script.Parent.Parent.Parent.Parent.Character.Box ~= nil then
            script.Parent.Parent.Parent.Parent.Character.Box:remove()
        elseif script.Parent.Parent.Parent.Parent.Character.Box == nil then
            game.Lighting.Box:Clone()
            game.Lighting.Box.Parent = script.Parent.Parent.Parent.Parent.Character
            wait()
            script.Parent.Parent.Parent.Parent.Character.Box.Torso.CFrame = CFrame.new(script.Parent.Parent.Parent.Parent.Character.Head.Position + Vector3.new(0, -5, -5))
        end

end


script.Parent.MouseButton1Click:connect(onButtonClicked)
1
JESUS IS LORD AND HE LOVES YOU!!! :D shasta342 37 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

The script is very confusing try defining some variables it will make your code easier to read, for you and for others, after you do that post the question again

Ad
Log in to vote
0
Answered by
Versimn 20
8 years ago
Edited 8 years ago

As TheTopBoss said, try defining variables to make your code easier to read (and faster).

local chr=game:GetService'Players'.LocalPlayer.Character
function onButtonClicked()
    if chr.Box then
        chr.Box:Destroy()
    end
    local box=game:GetService'Lighting'.Box:Clone()
    box.Parent=chr
    box.Torso.CFrame=CFrame.new(chr.Head.Position+Vector3.new(0, -5, -5))
end
script.Parent.MouseButton1Click:connect(onButtonClicked)

Answer this question