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

Script is not cloning the gui into the target?

Asked by 7 years ago
Edited 7 years ago
enabled = true
function onDamage(Part)
    if Part.Parent:FindFirstChild("Humanoid") ~= nil and enabled == true and Part.Parent.Name ~= script.Owner.Value then
        enabled = false
        script.Disabled = true
                local enemy = Part.Parent
        for i = 1,40 do
        enemy.Humanoid.Health = enemy.Humanoid.Health - 0.50
        wait(0.07)
        end
        game.ReplicatedStorage.Genjutsu:Clone().Parent = enemy.PlayerGui -- Gui Part
    end 
    wait(0.025)
end

script.Parent.Touched:connect(onDamage)

This script is a damage script that activates if you are inside a certain big block then this script activates and you should see a gui but it's not working /: please help me .

Thanks for your cooperation!

1 answer

Log in to vote
0
Answered by 7 years ago

Hello there, DarkWqlfc. lol

The reason your gui isn't cloning into the enemy is that you can't access the PlayerGui from the character.

Your enemy variable is a character.

To get the player from the character, use the :GetPlayerFromCharacter function.

Example: game.Players:GetPlayerFromCharacter(character)

Anyways, to fix your problem, I would make another variable for the PlayerGui:

enabled = true

function onDamage(Part)

    if Part.Parent:FindFirstChild("Humanoid") ~= nil and enabled == true and Part.Parent.Name ~= script.Owner.Value then
        enabled = false
        script.Disabled = true

        local enemy = Part.Parent
        local enemyGui = game.Players:GetPlayerFromCharacter(enemy).PlayerGui --New PlayerGui Variable

        for i = 1,40 do
            enemy.Humanoid.Health = enemy.Humanoid.Health - 0.50
            wait(0.07)
        end

        game.ReplicatedStorage.Genjutsu:Clone().Parent = enemyGui -- Gui Part

    end 

    wait(0.025)

end

script.Parent.Touched:connect(onDamage)

Playing around with this script, I noticed that the gui only pops up after damage is taken.

You might not want this.

To make it where the gui pops up while the damage is taken, clone the gui before the damage loop.

game.ReplicatedStorage.Genjutsu:Clone().Parent = enemyGui -- Gui Part       

for i = 1,40 do
        enemy.Humanoid.Health = enemy.Humanoid.Health - 0.50
    wait(0.07)
end

New Script:

enabled = true

function onDamage(Part)

    if Part.Parent:FindFirstChild("Humanoid") ~= nil and enabled == true and Part.Parent.Name ~= script.Owner.Value then
        enabled = false
        script.Disabled = true

        local enemy = Part.Parent
        local enemyGui = game.Players:GetPlayerFromCharacter(enemy).PlayerGui --New PlayerGui Variable

        game.ReplicatedStorage.Genjutsu:Clone().Parent = enemyGui -- Gui Part       

        for i = 1,40 do
            enemy.Humanoid.Health = enemy.Humanoid.Health - 0.50
            wait(0.07)
        end

    end 

    wait(0.025)

end

script.Parent.Touched:connect(onDamage)

0
Thanks for the help , but the method didn't work and it doesn't show in the output problems . DarkWQlfc 20 — 7y
0
I can help you on roblox through the messaging system. iiTylerSoul 56 — 7y
Ad

Answer this question