Hi, so in my towers they have a script when they’re placed they have a creator value being valued to the players name, and i made so that it gives cash everytime each shot they do, but somehow thats not always the case, somehow it makes error like ‘‘nil with leaderstats’’, so what is the exactly accurate way to fix this?
if target and player ~= nil and script.Parent.Placed.Value == true then
local playervalues = game.Players:FindFirstChild(player)
script.Parent.Torso.CFrame = CFrame.new(script.Parent.Torso.Position,target.Torso.Position)
target.Zombie:TakeDamage(script.Parent.CurrentDamage.Value/target.Defense.Value)
-- towertorso.Parent:SetPrimaryPartCFrame(CFrame.new(script.Parent.PrimaryPart.Position,target.Torso.Position))
playervalues.leaderstats.Coins.Value = playervalues.leaderstats.Coins.Value + script.Parent.CurrentDamage.Value
FireSound.PlaybackSpeed = 1
FireSound.SoundId = "rbxassetid://"..script.Parent.GunSound_ID.Value
FireSound.Parent = script.Parent.Torso
FireSound.Volume = 2
FireSound.TimePosition = 0
FireSound:Play()
humanim:Play()
print(damagenumber,'DMG to', target.Name)
end
it does give money though, but the problem is i need to solve it universally so it doesn’t make errors for other situation such as when they are stunned or deploy units near them. the error comes the whole time.
When I put this in the editor to debug it, many things were not definded. This isn’t a full script. You’ll have to define things to get it to work or have anyone help debug it other than just guessing at the problem.