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

This script only works the first time?

Asked by 8 years ago

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

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
8 years ago

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.

Ad
Log in to vote
-3
Answered by 8 years ago

Maybe it could be the debounce?

0
Are you kidding me Volodymyr2004 293 — 8y
0
Dont post an answer without reading the question Volodymyr2004 293 — 8y

Answer this question