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!
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)