GUI not replicating

I am trying to tween a GUI each time you kill an NPC that shows the money and exp you get and then it zooms across the screen to go into the correct gui that shows your money and exp. I have it working with the following script and I have the original GUI in StarterGui, but the problem is that if I kill another enemy right after the first (while the first gui is still on the screen) it ignores the 2nd gui. How can I fix this? I have moved things around, but the only other thing I can think of is putting the gui in replicated storage, but I can’t see how that would work any better. Thanks.

local hum = script.Parent:WaitForChild("Humanoid")
hum.Died:Connect(function()
local tag = hum:FindFirstChild("creator")
	if tag then
		local killer = tag.Value
		if killer then
			killer.leaderstats.Cash.Value = killer.leaderstats.Cash.Value + 50 + (killer.leaderstats.Rebirths.Value*50/10)
			killer.leaderstats.Experience.Value = killer.leaderstats.Experience.Value + 10 + (killer.leaderstats.Rebirths.Value*10/10)
			local score = killer.PlayerGui.Pickups:Clone()
			score.Name = "Score"
			score.Parent = killer.PlayerGui
			killer.PlayerGui.Score.Frame1.Cash.Text = "$"..(50 + (killer.leaderstats.Rebirths.Value*50/10))
			killer.PlayerGui.Score.Frame2.Exp.Text = 10 + (killer.leaderstats.Rebirths.Value*10/10).." EXP"
			killer.PlayerGui.Score.Enabled = true
			killer.PlayerGui.Score.Frame1.Cash:TweenSize(UDim2.new(1,0,1,0),.5)
			killer.PlayerGui.Score.Frame2.Exp:TweenSize(UDim2.new(1,0,1,0),.5)
			wait(1)
			killer.PlayerGui.Score.Frame1:TweenPosition(UDim2.new(0.3,0,0.1,0),Enum.EasingDirection.In,Enum.EasingStyle.Elastic,2)
			killer.PlayerGui.Score.Frame2:TweenPosition(UDim2.new(0.5,0,0,0),Enum.EasingDirection.In,Enum.EasingStyle.Elastic,1.9)
			wait(2)		
			killer.PlayerGui.Score:Destroy()
		end	
	end
end)
1 Like

Never mind, I got it working finally.
I always try to parent something I create AFTER changing it’s properties which is what I did originally, but because I tried to reference killer.PlayerGui.Score instead of the variable score, I was getting an error. I incorrectly moved the parenting of score up to before I called it and that is why I believe I was unable to create a new one while one was in progress. After I started using the variable score, I was able to move the parenting down until all the properties of the clone were altered.

local hum = script.Parent:WaitForChild("Humanoid")
hum.Died:Connect(function()
local tag = hum:FindFirstChild("creator")
	if tag then
		local killer = tag.Value
		if killer then
			killer.leaderstats.Cash.Value = killer.leaderstats.Cash.Value + 50 + (killer.leaderstats.Rebirths.Value*50/10)
			killer.leaderstats.Experience.Value = killer.leaderstats.Experience.Value + 10 + (killer.leaderstats.Rebirths.Value*10/10)
			local score = killer.PlayerGui.Pickups:Clone()
			score.Name = "Score"
			score.Frame1.Cash.Text = "$"..(50 + (killer.leaderstats.Rebirths.Value*50/10))
			score.Frame2.Exp.Text = 10 + (killer.leaderstats.Rebirths.Value*10/10).." EXP"
			score.Enabled = true
			score.Parent = killer.PlayerGui
			score.Frame1.Cash:TweenSize(UDim2.new(1,0,1,0),.5)
			score.Frame2.Exp:TweenSize(UDim2.new(1,0,1,0),.5)
			wait(1)
			score.Frame1:TweenPosition(UDim2.new(0.3,0,0.1,0),Enum.EasingDirection.In,Enum.EasingStyle.Elastic,2)
			score.Frame2:TweenPosition(UDim2.new(0.5,0,0,0),Enum.EasingDirection.In,Enum.EasingStyle.Elastic,1.9)
			wait(2)		
			score:Destroy()
		end	
	end
end)
1 Like