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

How would someone go about making a "Tag" function?

Asked by 5 years ago

Similar to the one in Jailbreak. I've tried countless times and none of them worked. Not meaning to ask anyone for the script but could anyone possible guide me through it?

On contact with another player a UI will pop in (I've already made it and tweened it) The ui says "Hold E To Tag"

1 answer

Log in to vote
0
Answered by 5 years ago

You should probably just check the distance between players instead of having each of their parts have a touched event and if you want it to be similar to jailbreak.

local runService = game:GetService("RunService")
local contextService = game:GetService("ContextActionService")

local ply = game.Players.LocalPlayer
local char = ply.Character
local ui = ply.PlayerGui.TagUi  --Assuming this is a ScreenGui

ply.CharacterAdded:connect(function(c)
    char = c
end)

function tweenUi()
    --Put Code to tween your Ui and tag progress 
end

function searchTarget() --Check if player is in range
    local dis = 3
    local tar = nil

    for _,v in pairs(game.Players:GetChildren()) do
        if v.Character and v.Character ~= char then
            local tDis = (v.Character.PrimaryPart.Position-char.PrimaryPart.Position).magnitude
            if tDis < dis then
                dis = tDis
                tar = v
            end
        end
    end
    if target then
        ui.Enabled = true
        target = tar
        contextService:BindAction("tagTween",tweenUi,false,Enum.KeyCode.E)  --Binding tag function to key
    else
        ui.Enabled = false
        contextService:UnbindAction("tagTween")
    end
end

runService:BindToRenderStep("findTarget",0,searchTarget)    --More functionality than while loop
Ad

Answer this question