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

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

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 comment

1

JESUS IS LORD AND HE LOVES YOU!!! :D

2 answers

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)

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