Still have questions? Join our Discord server and get real time help.
0

# 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...

0
Use a double equal sign '==' when performing a comparison like that. RobloxWhizYT 1852 — 9d
0
That also helps, but do you know why it won't work in general? Yosufgamer -7 — 9d
0
It doesn't work because of the equal sign, as far as I know. RobloxWhizYT 1852 — 9d
0
It says "invalid player to teleport" do you know how to fix this? Yosufgamer -7 — 9d
0
Try using a server script and getting the player another way. RobloxWhizYT 1852 — 9d
0
Specifically, use a RemoteEvent. RobloxWhizYT 1852 — 9d
0

0
Edited 9 days ago

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.

0
This is BS. I can guarantee you that it isn't his problem. RobloxWhizYT 1852 — 9d