Same question as title says. Everytime I add new print() it runs 3 times for some reason. Any idea whats the cause? Does that mean my script runs 3 times?:
Local-Script located in StarterCharacterScripts
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local RunService = game:GetService('RunService')
local Player = game:GetService('Players').LocalPlayer
local Character = Player.Character
local ProfileBars = Player.PlayerGui.ProfileWindow.Holder.StatsHolder
local HealthBar = ProfileBars.HealthBarHolder.BarBackground.HealthBar
local ManaBar = ProfileBars.ManaBarHolder.BarBackground.ManaBar
local StaminaBar = ProfileBars.StaminaBar
local HValue = ProfileBars.HealthBarHolder.HealthNum
local MValue = ProfileBars.ManaBarHolder.ManaNum
-- those prints im talking about
print(Character:GetAttribute('CurrentHealth'), Player)
print(Character:GetAttribute('CurrentMana'), Player)
function getHealth()
HValue.Text = Character:GetAttribute('CurrentHealth').."/"..(Character:WaitForChild('BaseStats'):GetAttribute('Health') + Character:WaitForChild('Stats'):GetAttribute('Endurance')/2)
end
function getMana()
MValue.Text = Character:GetAttribute('CurrentMana').."/"..(Character:WaitForChild('BaseStats'):GetAttribute('Mana') + Character:WaitForChild('Stats'):GetAttribute('Inteligence'))
end
function getEverything()
getHealth()
getMana()
end
getEverything()
Character.AttributeChanged:Connect(getEverything)
Character:WaitForChild('Stats').AttributeChanged:Connect(getEverything)
ReplicatedStorage.Events.UpdateHealth:FireServer(Player)
Attribute CurrentHealth and CurrentMana are created server-sided
Well, when you have it in StarterCharacterScripts, it generates new one every time your character loaded, while when you put it into StarterPlayerScripts, it is only loaded when player joins.
So that might cause some issues.
I tried putting in StarterCharacter, but I did not get multiple prints. I saw that you have health and mana and stuff, so I guess you’re making combat game, make sure none of the scripts respawn player (load character) for no reason. Also try respawning and see if its only when you join, or every time you respawn.
Even when I’ve removed StarterCharacter im getting those multiplied prints. Not a single script of mine have any respawn functions nor planning to add any soon. Checked if the same happens after character reset and nothing has changed. Also, I don’t think my health and mana stuff has something to do with it, because at the time of me writing this I have them disabled.
SOLUTION TO MY PROBLEM:
I have Viewport frame inside my GUIs that clones Player.Character to it for preview purposes. It clones everything including scripts. That means script inside my character and inside my cloned character is running. The best part about it is that my CLONE is generating ANOTHER CLONE of it for some reason. Thats why its running triple prints. I just have to delete every script inside my cloned character when clone is being created.
EDIT: I’ve found out about it after doing print(script) and checking its source