Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can you limit the amount of studs away you can see a billboard gui?

Asked by 10 years ago

I have an image label in a billboard gui. I don't want players to be able to see it from a far distance. Is there any way to do this? If not, is there something else I could try that's not a billboard gui but will act like one?

After reading another post, I have now learned that I can use the DistanceFromCharacter() function. I have never used this, so how might the script look to limit the player's ability from seeing the billboard gui 100 studs away?

1 answer

Log in to vote
0
Answered by
drahsid5 250 Moderation Voter
10 years ago

Yes. This s quite simple actually. All you need to do is raycast.

Plr = Game.Players.LocalPlayer
Ray = Ray.new(
(Plr.Character.Torso.CFrame*CFrame.new(0, 0, 0)).p,
(Game.Workspace.BillBoardPart.CFrame*CFrame.new(0,0,0)).p --Wherever the part containing the billboard is.
)

And now, detect the distance.

local hit, position = game.Workspace:FindPartOnRay(Ray, Plr.Character)
Dist = (Plr.Character.Torso.Position - position).Magnitude

Now, we disable/enable it.

if Dist > 500 then --500 = the distance
Game.Workspace.BillBoardPart.BillboardGui.Enabled = false
elseif Dist < 500 then Game.Workspace.BillBoardPart.BillboardGui.Enabled = true
end

And we're done.

Plr = Game.Players.LocalPlayer
Ray = Ray.new(
(Plr.Character.Torso.CFrame*CFrame.new(0, 0, 0)).p,
(Game.Workspace.BillBoardPart.CFrame*CFrame.new(0,0,0)).p --Wherever the part containing the billboard is.
)

local hit, position = game.Workspace:FindPartOnRay(Ray, Plr.Character)
Dist = (Plr.Character.Torso.Position - position).Magnitude

if Dist > 500 then --500 = the distance
Game.Workspace.BillBoardPart.BillboardGui.Enabled = false
elseif Dist < 500 then Game.Workspace.BillBoardPart.BillboardGui.Enabled = true
end
Ad

Answer this question