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

How can you make a button run a specific code i tried and it didn't work??

When I click on a button it should run a code and when I click again it should do something else but it just gets confused and does something random, how would I fix this?

The local script under the button:

local button = script.Parent
local frame = script.Parent.Parent.Parent.Trolling_UI
local status = script.Parent.Parent.status

button.MouseButton1Click:Connect(function()
	wait(0.1)
	button.Image = "rbxassetid://2691049520"
	frame.Position = UDim2.new(0.708, 0,0.621, 0)
	frame.Size = UDim2.new(0, 261,0, 230)
	status.Position = UDim2.new(0.323, 0,0.138, 0)
	status.Visible = true
	status.Text = "Computer mode on"
	wait(0.8)
	status.Visible = false
end)


button.MouseButton1Click:Connect(function()
	wait(0.1)
	button.Image = "rbxassetid://2782203344"
	frame.Position = UDim2.new(0.33, 0,-0.003, 0)
	frame.Size = UDim2.new(0, 264,0, 173)
	status.Position = UDim2.new(0.307, 0,0.700, 0)
	status.Visible = true
	status.Text = "Phone mode on"
	wait(0.8)
	status.Visible = false
end)

Thanks in advance!

1 answer

✓ Accepted answer

Currently, the compiler doesn't know which function to run when the button is clicked because there are two of them. I would consider doing something like this:

local button = script.Parent
local frame = script.Parent.Parent.Parent.Trolling_UI
local status = script.Parent.Parent.status

button.MouseButton1Click:Connect(function()
    wait(0.1)
    if status.Text = "Phone mode on" then
	    button.Image = "rbxassetid://2691049520"
	    frame.Position = UDim2.new(0.708, 0,0.621, 0)
	    frame.Size = UDim2.new(0, 261,0, 230)
	    status.Position = UDim2.new(0.323, 0,0.138, 0)
	    status.Visible = true
	    status.Text = "Computer mode on"
	    wait(0.8)
	    status.Visible = false
    else
	    button.Image = "rbxassetid://2782203344"
  	    frame.Position = UDim2.new(0.33, 0,-0.003, 0)
	    frame.Size = UDim2.new(0, 264,0, 173)
 	    status.Position = UDim2.new(0.307, 0,0.700, 0)
 	    status.Visible = true
	    status.Text = "Phone mode on"
	    wait(0.8)
 	    status.Visible = false
    end
    end
end)

1 comment

1

Thank You! corncob567

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