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

This script only works the first time?

Hi so I'm making a game where when you mouse over a brick, a bigger brick appears on top of it. This only happens when a mode is activated (aka a bool value.) Then when you click a separate brick, it removes that bigger brick (script for that not included.) Here is the script which is a child of the script that you are supposed to mouse over. Yeah, it works fine the first time, but after I press the remove button (the brick does get removed) It does not show up again.

local part = script.Parent.Parent
local pos=script.Parent.Head.Position
debounce = false

script.Parent.Head.ClickDetector.MouseHoverEnter:connect(function(playerwhoclicked)
		if script.Parent.Parent.Object.Value~="nothing" then
			if debounce==false then
				debounce=true
				local ghosty=part.GhostObjects:FindFirstChild(part.Object.Value)
				ghosty:MoveTo(pos)
				script.Parent.ghostObjecty.Value=(part.Object.Value)
				debounce=false			
			end
		end
end)

Let me break it down to avoid confusion: Since the bigger brick is picked randomly out of a set of two, I have them both in a model inside of "part", (a model) the same "part" that is the Parent of the Parent of this script. This script is in a model inside of part. Inside that same model is a brick named Head. Head is the brick that your mouse is supposed to move over. The object string value that is inside of part states which brick was randomly chosen. When this brick is randomly chosen, it is transported to a model inside of part called GhostObjects. Don't worry about the ghostObjecty value, it's just for me to make sure that the script works. Just to make it clear: it is not changed the second time, highlighting that it does not work. Sorry for making my question this long. But I hope that explains it enough.

2 answers

Your hierarchy is a bit confusing, so definitely try to simplify that if possible. But take another look at these lines;

local ghosty=part.GhostObjects:FindFirstChild(part.Object.Value)
ghosty:MoveTo(pos)

So you're moving a specific part. Then, in your other script, you're destroying that part. Now it can't run again, because the part isn't there.

Clone the part you want, then move and destroy the clone.

local ghosty=part.GhostObjects:Clone()
ghosty.Name = "GhostClone"
ghosty.Parent = part.GhostObjects
ghosty:MoveTo(pos)

Something like that.

Maybe it could be the debounce?

2 comments

0

Are you kidding me

0

Dont post an answer without reading the question

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