How to clone a gui to player screen when got hit by somthing

I want to make player can’t see for a while when player got hit

local function Gothahahaha(Player)
	local Character = Player.Character
	local hitbox = script.HitBox:Clone()
	hitbox.Parent = workspace
	hitbox.CFrame = Character.PrimaryPart.CFrame * CFrame.new(0,0, (hitbox.Size.z/2)*-1)
	local wee = Instance.new("WeldConstraint")
	wee.Part0 = hitbox
	wee.Part1 = Character.PrimaryPart
	wee.Parent = hitbox
	De:AddItem(hitbox,.65)
	local ignorelist = {}
	hitbox.Touched:Connect(function(hitted)
		if hitted.Parent:FindFirstChild("HumanoidRootPart") and not hitted:IsDescendantOf(Character) then
			local enemy = hitted.Parent
			if (table.find(ignorelist,enemy)) == nil then
				table.insert(ignorelist,enemy)
				wait(.3)
				enemy.Humanoid:TakeDamage(Damage)
				local bv = Instance.new("BodyVelocity")
				bv.MaxForce = Vector3.new(1e6,1e6,1e6)
				bv.Velocity = Character.PrimaryPart.CFrame.LookVector * 5
				bv.Parent = enemy.PrimaryPart
				De:AddItem(bv,.2)
				script.ScreenGui:Clone().Parent = enemy
				enemy.Humanoid:LoadAnimation(script.StarHit):Play()
				
			end
		end
	end)
end

Because you’re trying to clone the GUI into the character. You should be trying to clone the GUI into the Player’s PlayerGUI.

So it would be something like:

local getPlayer = game.Players:GetPlayerFromCharacter(enemy)
local cloned = script.ScreenGui:Clone()
cloned.Parent = getPlayer.PlayerGui

Getting the Player object from the character >> cloning the Gui into the player’s PlayerGui

1 Like

Thank you very much that works

2 Likes