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

AssassinUI refusing to load the next character?

Asked by 5 years ago

Hello; I'm trying to work on an AssassinUI and I've run into a complication with the character not loading properly and it only working once with the first character that it loads. Was trying to find out a solution before resorting to here but I've got nothing. Any help or aid to help fix this is appreciated! =)

p.s. There is no real line error it just doesnt load the actual target character somewhere near line 48 and above.

local SP = script.Parent
local Player = game.Players.LocalPlayer
wait(0.5)
local CurrentCamera = workspace.CurrentCamera
local Marketplace = game:GetService("MarketplaceService")
local GamepassId = 6800421
local HUD = SP.HUDPlayer

local SuccessfullEvent = game.ReplicatedStorage.RemoteEvents.SuccessfullKill
local Target

local function GetTarget()
    repeat wait(1)
        local randomPlayer = game.Players:GetPlayers()[math.random(1,#game.Players:GetPlayers())]
        Target = randomPlayer
    until randomPlayer.Name ~= Player.Name and randomPlayer.Team.Name ~= Player.Team.Name
end

local function Initiate()
    if --[[Marketplace:UserOwnsGamePassAsync(Player.UserId, GamepassId) and]] Player.TeamColor == BrickColor.new("Bright red") then
        script.Parent.HUDPlayer.Visible = true
        GetTarget()
        print(Target)
        if Target ~= nil and Target.Character ~= nil then
            local content, bool = game.Players:GetUserThumbnailAsync(Target.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size150x150)
            HUD.TargetName.Text = Target.Name
            HUD.TargetTeam.Text = Target.Team.Name
            HUD.TargetPicture.Image = content
            Target.Character.Humanoid.HealthChanged:Connect(function(Health)
                print(Health)
                if Health <= 0 then
                    wait(3)
                    if Target == nil then
                    return end
                end
                    Health = 100
                local hp = Health/Target.Character.Humanoid.MaxHealth
                script.Parent.HUDPlayer.TargetHP.Frame:TweenSize(UDim2.new(hp,0,1,0),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,0.15)
            end)
        end
    else
        script.Parent:Destroy()
    end
end

Initiate()

Target.Character.Humanoid.Died:Connect(function()
    print("target died")
    if Target.Character.Humanoid:FindFirstChild("creator") ~= nil then
        print("found")
        if Target.Character.Humanoid:FindFirstChild("creator").Value == Player.Name then
            print("successful")
            SuccessfullEvent:FireServer("KilledPlayer",Target)
        else
            print("target died")
            HUD.TargetName.Text = "Target has Died"
            HUD.TargetTeam.Text = "Obtaining new Target..."
            HUD.TargetPicture.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&userId=1"   
            wait(1)
            Target = nil
            Initiate()      
        end
    end 
end)

SuccessfullEvent.OnClientEvent:Connect(function(Parameter)
    if Parameter == "Return" then
        Initiate()
    end
end)

game.Players.PlayerRemoving:Connect(function(Player)
    if Target then
        Target = nil
        HUD.TargetName.Text = "Target has left game"
        HUD.TargetTeam.Text = "Obtaining new Target"
        HUD.TargetPicture.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&userId=1"
        wait(1)
        Initiate()
    end
end)


Answer this question