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

TextButton script in Surface GUI are not activating, any ideas?

Ok, so in in the workspace I have a HingeConstraint and 3 surface GUIs. The surface GUIs are all in one part. The following script is inside one of the TextButtons. The script is NOT a localscript.

local drawhinge = game.Workspace.Walls.Gatehouse.Draw.HingeConstraint --Path to HingeConstraint

local close = script.Parent.Parent.Parent.Close.Close --Path to other TextButton
local open = script.Parent --Path to this TextButton
local statusbar = script.Parent.Parent.Parent.SurfaceGui.statusbar --Path to statusbar textlabel


script.Parent.Activated:Connect(function() --Connect on Activation
	print("Activated")--Check if it activated
	print("Opening")--Indicate that drawbridge is opening
	close.Visible = false --Make other textbutton invisible so it cant be clicked
	drawhinge.AngularVelocity = drawhinge.AngularVelocity - 5 --Open drawbridge
	statusbar.Text = "Opening..." --Make the status bar indicate that the drawbridge is opening
	wait(4)--Wait for it to open
	drawhinge.AngularVelocity = 0 --Stop opening Drawbridge
	close.Visible = true --Make other textbutton visible again
	statusbar.Text = "Open" --Make the status bar indicate that the drawbridge is open
	print("Open")--State that the drawbridge is open
end)

When i go in output and test it out, not even the print("activated") function runs. It seems that the textbutton function isn't activating when i click it, and i dont know why.

1 answer

✓ Accepted answer

Is "script.Parent" the textbutton? Because from what I know the event when a textbutton is clicked is .MouseButton1Click. So the script will be like:

local drawhinge = game.Workspace.Walls.Gatehouse.Draw.HingeConstraint --Path to HingeConstraint

local close = script.Parent.Parent.Parent.Close.Close --Path to other TextButton
local open = script.Parent --Path to this TextButton
local statusbar = script.Parent.Parent.Parent.SurfaceGui.statusbar --Path to statusbar textlabel


script.Parent.MouseButton1Click:Connect(function() --Connect on Activation
    print("Activated")--Check if it activated
    print("Opening")--Indicate that drawbridge is opening
    close.Visible = false --Make other textbutton invisible so it cant be clicked
    drawhinge.AngularVelocity = drawhinge.AngularVelocity - 5 --Open drawbridge
    statusbar.Text = "Opening..." --Make the status bar indicate that the drawbridge is opening
    wait(4)--Wait for it to open
    drawhinge.AngularVelocity = 0 --Stop opening Drawbridge
    close.Visible = true --Make other textbutton visible again
    statusbar.Text = "Open" --Make the status bar indicate that the drawbridge is open
    print("Open")--State that the drawbridge is open
end)

1 comment

0

yes the textbutton is script.parent

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