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

Why isn't Player:DistanceFromCharacter working?

local player = game.Players.LocalPlayer
local runService = game:GetService("RunService")
local guiPart = workspace.MultiplayerComingSoon

local nearPart = false

runService.RenderStepped:Connect(function()
	if player:DistanceFromCharacter(guiPart.Position) < 2 then
		nearPart = true
		workspace.MultiplayerComingSoon.BillboardGui.TextLabel.Visible = true
	else
		nearPart = false
		workspace.MultiplayerComingSoon.BillboardGui.TextLabel.Visible = false
	end
end)

I started scripting a couple weeks ago, I've been kind of off and on and haven't really focused on learning much since I started. Anyways, I'm trying to make it to where a text label pops up saying "Multiplayer is coming soon" when the player is near a part used for multiplayer. I've read up on it a little bit and I've seen all this magnitude stuff, not sure how to go about it. Any suggestions on making this work?

1 answer

dont even need DistanceFromCharacter just do this.

local player = game.Players.LocalPlayer
local runService = game:GetService("RunService")
local guiPart = workspace.MultiplayerComingSoon

local nearPart = false

runService.RenderStepped:Connect(function()
    if (player.Character:WaitForChild("HumanoidRootPart").Position - guiPart.Position).Magnitude < 2 then
        nearPart = true
        workspace.MultiplayerComingSoon.BillboardGui.TextLabel.Visible = true
    else
        nearPart = false
        workspace.MultiplayerComingSoon.BillboardGui.TextLabel.Visible = false
    end
end)

1 comment

0

Magnitude is just as effective and more versatile as it can be used for any physical instance :]

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