I currently have a white rectangle that contains a red rectangle in the middle, basically there is a black rectangle at the start that keeps moving to it's right. The player must press B when the black is in the center.
Currently there are no errors showing up in output but there is something wrong, i'm using a print() function to test it and nothing prints.
Also, I was wondering if there was a property/easier way to detect contact from one text label to another to clear up my cluttered if-then statement.
I'm out of ideas and I don't know what to do. Here's the code:
repeat wait() until game.Players.LocalPlayer --Waits for the Player
local player = script.Parent.Parent --Player
local mouse = player:GetMouse() --Get the player's mouse.
mouse.KeyDown:connect(function(key) --Function
if key == "b" then --Waits for the key to be pressed, once it is, the statement if fired.
player.PlayerGui.ReversalGui.Frame.Bar.LocalScript1.Disabled = true
wait(0.25)
if player.PlayerGui.ReversalGui.Frame.Bar.Position == UDim2.new(0.2, 0, 0, 0) or player.PlayerGui.ReversalGui.Frame.Bar.Position == UDim2.new(0.24, 0, 0, 0) or player.PlayerGui.ReversalGui.Frame.Bar.Position == UDim2.new(0.28, 0, 0, 0) or player.PlayerGui.ReversalGui.Frame.Bar.Position == UDim2.new(0.32, 0, 0, 0) or player.PlayerGui.ReversalGui.Frame.Bar.Position == UDim2.new(0.36, 0, 0, 0) or player.PlayerGui.ReversalGui.Frame.Bar.Position == UDim2.new(0.4, 0, 0, 0) or player.PlayerGui.ReversalGui.Frame.Bar.Position == UDim2.new(0.44, 0, 0, 0) or player.PlayerGui.ReversalGui.Frame.Bar.Position == UDim2.new(0.48, 0, 0, 0) or player.PlayerGui.ReversalGui.Frame.Bar.Position == UDim2.new(0.52, 0, 0, 0) or player.PlayerGui.ReversalGui.Frame.Bar.Position == UDim2.new(0.56, 0, 0, 0) or player.PlayerGui.ReversalGui.Frame.Bar.Position == UDim2.new(0.6, 0, 0, 0) or player.PlayerGui.ReversalGui.Frame.Bar.Position == UDim2.new(0.64, 0, 0, 0) or player.PlayerGui.ReversalGui.Frame.Bar.Position == UDim2.new(0.68, 0, 0, 0) then --This is what I was referring to earlier
print("work") --Printing check to make sure it works.
end
end
end)
I'd really appreciate some help. I've looked at the Wiki page for UDim2 already so I honestly don't know what to do.
-Nap516

2 comments
The LocalPlayer will always exist
Use UserInputService (InputBegan, InputEnded) to detect keystrokes instead of KeyDown. It's not printing because one of the if statements are not going through. Suggest to add another test print inside the first if statement to double check if that ones working/not.