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

How do I make this "if, then" script work with a mouse click teleport on a gui button?

Hey, so I am trying to make this button only work when the background transparency is equal to 0, I am having some trouble with that though mainly because I am pretty bad at coding..

Here is the code I am trying to make work for this.


button = script.Parent

if button.BackgroundTransparency = 0 then

tele = game:GetService('TeleportService')
button.MouseButton1Down:connect(function()
local player = game.Players.LocalPlayer
tele:Teleport(2561674732, player)

end)

end

Any help would be appreciated, sorry it's bad...

7 comments

0

Use a double equal sign '==' when performing a comparison like that.

0

That also helps, but do you know why it won't work in general?

0

It doesn't work because of the equal sign, as far as I know.

0

It says "invalid player to teleport" do you know how to fix this?

0

Try using a server script and getting the player another way.

0

Specifically, use a RemoteEvent.

0

Please put solved in your title [SOLVED]

1 answer

The reason this doesn't work at all is because it isn't setting the MouseButton1Click event at all.

button.MouseButton1Click:Connect(function()
    if (button.Transparency == 0) then
	    --teleport stuff
    end
end

The event is applied to where everytime it is clicked it will trigger and check the transparency. I wouldn't use transparency to check it. You should be using variables outside and changing accordingly. There also might be issues when comparing values. The transparencies might not be consistent. It may seem to be set to 0, but it can end up like 0.0000001 or some small difference that would make it not pass the if statement.

1 comment

0

This is BS. I can guarantee you that it isn't his problem.

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