I am a noobie when it comes to scripting and don’t know much however I want to make a radar GUI for FPS games so that it shows on the minimap you and your teammates as dots on the minimap of the game map. I have made everything so far but I want to make it so that enemy tags only appear if the player has directly looked at the enemy player, so that it shows on the minimap, and goes away if the player loses sight of the enemy. What function can I use to achieve this? Thank you very much.
Maybe casting a Ray to the direction the Player is aiming, check if the hit result player belongs to enemies, then place the dot, and after some time, delete the dot unless the player did hit the ray again on that player
Raycast is good but, there is other way tho, also works:
local Mouse = plr:GetMouse() -- the mouse
local distancefromEnemy
local enemy = Mouse.Target
-- enemy is a variable ( for reference, it will get
--The model, part, actually, what you are aiming )
local antiSpam = false -- if you do not insert this, after sliding over the same part or
-- enemy, it will just cause some lag spikes, because it will ''fire '' each time, with
--this debounce, it will prevent spamming until the player stops hovering the part or whatever
UIS.InputChanged:Connect(function()
if Mouse.Target and Mouse.Target:FindFirstChild("RadarTagged")
-- RadarTagged is a ("StringValue") inside the model or part,
--but you can do that with
-- Collection Service ( not going into details,
--but prevents from creating alot of stringvalues inside of each part ,
--i recommend looking later at this, for now,
--you can test the stringvalue to see if it will work as you wish)
enemy = Mouse.Target -- Reference will be transformed into what you are aiming at
distancefromEnemy = plr:DistanceFromCharacter(enemy.Position)
-- for the sake of anti exploit or something else, do this [Server-sided],
--client side is only for visuals and prevent any weird visual behavior
-- ( makes more efficient for the player since the server has a
--lil delay to receive some information)
-- only use it if you wish to have a maximum distance, if not, just delete it
if distancefromEnemy < 100 and distancefromEnemy ~= nil then
if antiSpam == true then
return
end
antiSpam = true
--print("distance allowed")
--FoundEnemy:FireServer(player, enemy) -- will send the enemy that was found
-- script your stuff here,
-- you can use the ''enemy'' reference to send to the server, also, don't forget to active on the radar
-- depending on how your game is, you can just turn on the Dot VISIBLE on the mini map
--EnemyDot.Visible = true
--YourGui.Visible = true <
if multiple targets, then it will be kinda advanced stuff
end
end
end)
more explanation, to make it simple
if your ‘‘Enemy’’ or model or part has something inside called “RadarTagged” – the stringvalue
the findfirstchild will see if this model or enemy has it, if not, then it will not detect anything
this is good for some exceptions if you wish
so, while aiming with a gun, after your mouse gets the ‘‘model of the player’’ CAN BE ANYTHING
it will activate the function (don’t forget about the distance)
you can turn on the ‘‘GUI.visible’’ can be anything, any symbol or stuff, just turn it on,
since probally you will be using a mini map (2D)
i think, you can create, for each player, their own dots, if you are worried about hackers
make sure the server inserts a ‘‘RadarTag’’ inside of each model of each player in the game
so they will not be able to destroy it
(PlayerAdded FUNCTION above)
the thing is, abou7t the mini map, idk how to explain ,i only know how to make a reference and show it
(did you know that you can create a billboard GUI ( like some GUI used for Titles in games)
you can enable and turn it visible (don’t forget about Adornee)
and it will show him from any location, its kinda usefull, but for the minimap this is not usefull
this guy has the radar
the only stuff you will need to change is: turn off the DOTS gui, so it will not be visible any dot, until you aim with the mouse
wow thank you very much. This helped me a lot more than needed and I sincerely thank you for that.
wait so I need to do this server sided? Also what will it do if it is all client sided? I am sorry if this question sounds dumb I don’t know coding that well.
Here is what I got so far for my code. I know I did something wrong because it does not work and it lags my game. Im doing this on a test place with NPC dummies but it does not work, the dummies have the RadarTagged inside of them.
local radarBG = script.Parent:WaitForChild(“BackgroundCircle”)
local playerDotTemplate = game.ReplicatedStorage:WaitForChild(“PlayerDot”)
local UIS = game:GetService(“UserInputService”)
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local Mouse = plr:GetMouse() – the mouse
local distancefromEnemy
local target = Mouse.Target
– enemy is a variable ( for reference, it will get
–The model, part, actually, what you are aiming )
local antiSpam = false
game:GetService(“RunService”).RenderStepped:Connect(function()
radarBG:ClearAllChildren()
local uiAspectRatioConstraint = Instance.new("UIAspectRatioConstraint", radarBG)
for i, otherPlayer in pairs(game.Players:GetPlayers()) do
local otherChar = otherPlayer.Character
if otherPlayer ~= plr then
if otherChar and otherChar:FindFirstChild("HumanoidRootPart") and char:FindFirstChild("HumanoidRootPart") then
local playerDot = playerDotTemplate:Clone()
local offset = otherChar.HumanoidRootPart.Position - char.HumanoidRootPart.Position
local distance = 1/200
offset = offset * distance
playerDot.Position = UDim2.new(offset.X + 0.5, 0, offset.Z + 0.5, 0)
playerDot.Parent = radarBG
end
else
local playerDot = playerDotTemplate:Clone()
playerDot.Position = UDim2.new(0.5, 0, 0.5, 0)
playerDot.Parent = radarBG
end
end
for i, humanoid in pairs(game.Workspace:GetChildren()) do
local otherChar = humanoid
if otherChar and otherChar:FindFirstChild("HumanoidRootPart") and char:FindFirstChild("HumanoidRootPart") and otherChar.Name ~= plr.Name and otherChar:FindFirstChildWhichIsA("Humanoid").Health ~= 0 then
end
end
UIS.InputChanged:Connect(function()
if Mouse.Target and Mouse.Target:FindFirstChild("RadarTagged") and Mouse.Target:FindFirstChild("Humanoid") and Mouse.Target:FindFirstChild("HumanoidRootPart") then
print("Target Found")
-- RadarTagged is a ("StringValue") inside the model or part,
--but you can do that with
-- Collection Service ( not going into details,
--but prevents from creating alot of stringvalues inside of each part ,
--i recommend looking later at this, for now,
--you can test the stringvalue to see if it will work as you wish)
target = Mouse.Target -- Reference will be transformed into what you are aiming at
distancefromEnemy = plr:DistanceFromCharacter(target.Position)
-- for the sake of anti exploit or something else, do this [Server-sided],
--client side is only for visuals and prevent any weird visual behavior
-- ( makes more efficient for the player since the server has a
--lil delay to receive some information)
-- only use it if you wish to have a maximum distance, if not, just delete it
if distancefromEnemy < 100 and distancefromEnemy ~= nil then
if antiSpam == true then
return
end
antiSpam = true
print("distance allowed")
--FoundEnemy:FireServer(plr, enemy) -- will send the enemy that was found
-- script your stuff here,
-- you can use the ''enemy'' reference to send to the server, also, don't forget to active on the radar
-- depending on how your game is, you can just turn on the Dot VISIBLE on the mini map
local playerDot = playerDotTemplate:Clone()
local offset = target:FindFirstChild("HumanoidRootPart").Position - char.HumanoidRootPart.Position
local distance = 1/200
offset = offset * distance
playerDot.Position = UDim2.new(offset.X + 0.5, 0, offset.Z + 0.5, 0)
playerDot.ImageColor3 = Color3.fromRGB(255, 0, 0)
playerDot.ImageColor3 = Color3.fromRGB(255,0,0)
playerDot.Parent = radarBG
end
end
end)
end)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.