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)
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
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)