So basically this script is supposed to be so when you collect a coin, it gives you a certain amount of coins then removes itself. I am trying to make it so if they have a certain upgrade they get more money from the coins but when I collect it, it gives me no cash even though I set my multiplier to 10.
local baseamount = 10 script.Parent.Touched:Connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if hit.Parent:FindFirstChild("Humanoid") then local multvalue = player.extra.multiplier.Value local multipler = baseamount * multvalue player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + multipler script.Parent:Destroy() end end)
Try this:
local baseamount = 10 script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local player = game.Players:GetPlayerFromCharacter(hit.Parent) local extraPoints = player:FindFirstChild("extra") if extraPoints ~= nil then local multvalue = extraPoints.multiplier.Value player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + multvalue*baseamount else player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + baseamount end script.Parent:Destroy() end end)
I changed some things:
I think the script should check for the humanoid before getting the player from the character.
I made the script respond to both scenarios: If there is an "extra" and if there isn't. If there is, give the player the score times the player's multiplier value. If there's no extra, just give the baseamount.
I put script.Parent:Destroy() outside the "if extra ~= nil" expression. Since it should happen no matter what the scenario.