✓ Accepted answer
Well, first we need to get the distance between the player and the block.
player = game.Players.LocalPlayer
if not player.Character then player.CharacterAdded:wait() end
char = player.Character
block = game.Workspace:WaitForChild("Block")
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.
player = game.Players.LocalPlayer
if not player.Character then player.CharacterAdded:wait() end
char = player.Character
block = game.Workspace:WaitForChild("Block")
maxDistance = 10
gui =
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.
player = game.Players.LocalPlayer
if not player.Character then player.CharacterAdded:wait() end
char = player.Character
block = game.Workspace:WaitForChild("Block")
maxDistance = 10
gui =
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
end
end)
Perfect! UserInputService FTW! And magnitude
2 comments
Pretty good, but may need some explaining, since, like he said, he is ignorant of how this works.
Wow, I wasn't expecting such an in depth response. Thank you very much!!