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

why are my scripts broken?

When the scripts parent is pressed it makes a part invisible this script used to work in the actual play mode but now it only works in roblox studio i don't understand why. be VERY SPECIFIC STEP BY STEP when explaining the problem

Debounce=false
function onClicked()
	if not Debounce then
		Debounce=true

	script.Parent.BrickColor=BrickColor.new("Really red")
	Workspace.invisibleD.Transparency=1
	Workspace.invisibleD.CanCollide=false
	wait(3)
	Workspace.invisibleD.Transparency=0
	Workspace.invisibleD.CanCollide=true
	wait(5)
	script.Parent.BrickColor=BrickColor.new("Lime green")
	Debounce=false
end

end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

This is another script when a gui button is clicked its suppose to open a frame

script.Parent.MouseButton1Click:connect(function()
	script.Parent.Parent.Frame.Visible=true
	script.Parent.Parent.Frame.VoteText.Visible=true
	script.Parent.Parent.Frame.CloseButton.Visible=true
	
end)

2 answers

✓ Accepted answer

Probably the pathfinding common problem, please consider looking through old questions before posting.

Possible solution

You can't just use script.Parent.Parent.Parent.Parent to do certain things, the possibilities of your script to break could increase.

You really never know whenever one of these "Parent.Parent.Parent.Parent..." doesn't exist yet or just doesn't exist.

This is why Part:WaitForChild("Noob") and Part:FindFirstChild("AnotherNoob") are useful.

3 comments

0

i dont really get how to use Part:WaitForChild() or Part:FindFirstCHild to fit into my script giving me an example would be nice.

0

Sure, WaitForChild waits for a children with a specific name, because you never know if the script you just made will run before the objects appear, so it waits for them first, pausing the current thread, if it already exists then it will instantly recognize it. FindFirstChild FINDS a child with a specific name instantly, if it doesn't exist it will return nil so you can use if Part:FindFirstChil

0

if Part:FindFirstChild("lol") then or if Part:FindFirstChild("lol")==nil then

I agree with 6Pen, maybe the object is nil, meaning the Frame doesnt exist, like you added too many or too much parents. So try doing something like this incase the script breaks:

 function onClicked()
    if not Debounce then
        Debounce=true
    script.Parent.BrickColor=BrickColor.new("Really red")
    Workspace.invisibleD.Transparency=1
    Workspace.invisibleD.CanCollide=false
    wait(3)
    Workspace.invisibleD.Transparency=0
    Workspace.invisibleD.CanCollide=true
    wait(5)
    script.Parent.BrickColor=BrickColor.new("Lime green")
    Debounce=false
end
script.Parent.MouseButton1Click:connect(function()
if script.Parent.Parent:findFirstChild("Frame") then
	onClicked()
end
end)


 

2 comments

0

this used to work and all the sudden it doesnt and the frame has to exist

0

Maybe you changed the frame's parent perhaps?

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