Hi all! I usually have a base line idea of where to start with my problems, but this one I have no idea.
Here's what I want to accomplish: When the Player is within X distance of a block... A text gui will pop up on their screen and The script will respond if a certain key is pushed, in this case spacebar
Any help is greatly appreciated, I have very little experience with magnitude and keystrokes.
Well, first we need to get the distance between the player and the block.
--in a localScript player = game.Players.LocalPlayer if not player.Character then player.CharacterAdded:wait() end char = player.Character block = game.Workspace:WaitForChild("Block") --or something maxDistance = 10 char.Torso.Changed:connect(function(prop) if prop == "CFrame" then local dis = (block.Position-char.Torso.Position).magnitude if dis <= maxDistance then end end end)
Well great! Now we have the distance between the player and the block.
Next, we need to get the gui visible.
--in a localScript player = game.Players.LocalPlayer if not player.Character then player.CharacterAdded:wait() end char = player.Character block = game.Workspace:WaitForChild("Block") --or something maxDistance = 10 gui = --something char.Torso.Changed:connect(function(prop) if prop == "CFrame" then local dis = (block.Position-char.Torso.Position).magnitude if dis <= maxDistance then gui.Visible = true else gui.Visible = false end end end)
Perfect! Now for the space press.
--in a localScript player = game.Players.LocalPlayer if not player.Character then player.CharacterAdded:wait() end char = player.Character block = game.Workspace:WaitForChild("Block") --or something maxDistance = 10 gui = --something char.Torso.Changed:connect(function(prop) if prop == "CFrame" then local dis = (block.Position-char.Torso.Position).magnitude if dis <= maxDistance then gui.Visible = true end end end) game:GetService("UserInputService").InputBegan:connect(function(key,gameThing) if key.KeyCode == Enum.KeyCode.Space and not gameThing and gui.Visible then --do stuff end end)
Perfect! UserInputService FTW! And magnitude