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

Why is my Roblox studio crashes when i click the part?

Asked by 2 years ago
Edited 2 years ago

so i want to make a part that if you click it a textlabel in another part visible but when i click it my roblox studio crashes

this is my script:

local Text = game.Workspace.CLICKTHIS.SurfaceGui.TextLabel.Visible

function OnClicked()
    if OnClicked() then
        wait(3)
        Text = true
    end

end

script.Parent.ClickDetector.MouseClick:Connect(OnClicked)

1 answer

Log in to vote
1
Answered by
JesseSong 3916 Moderation Voter Community Moderator
2 years ago
Edited 2 years ago

Problem:

The error is caused by a stack overflow. On your function onClicked, a recursion is happening which never ends or repeat.

What is a stack overflow?

A stack overflow is a problem faced when using stacks. It occurs when the stack grows larger than the area it has been allocated.

Solution:

Just remove the onClicked() function on line 4, and this should work!


local Text = game.Workspace.CLICKTHIS.SurfaceGui.TextLabel.Visible function OnClicked() wait(1) -- the amount of secs you want this to run! print ("hello") Text = true end script.Parent.ClickDetector.MouseClick:Connect(OnClicked)

Resources:

Stacks

Similar Question

Ask me if you have more questions

Ad

Answer this question