so my goal here is that when you touch the part you get teleported, get 50 cash depending on how many rebirths you have. But when i have 1 rebirth, and i touch the part, it gives me 50 cash instead of 100 cash. Here's the script:
script.Parent.Touched:Connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) local leaderstats = player:WaitForChild("leaderstats") local Cash = leaderstats.Cash local Rebirths = leaderstats.Rebirths local Gems = leaderstats.Gems if Rebirths.Value > 0 then Cash.Value = Cash.Value + (50*(Rebirths.Value + 1)) Gems.Value = Gems.Value + Rebirths.Value else Cash.Value = Cash.Value + 50 end player.Character:SetPrimaryPartCFrame(CFrame.new(script.Parent.Parent.TeleportPart.Position)) end)
Can someone help me fix this problem? Or maybe even explain why i got the script wrong?
Try to do it like this:
script.Parent.Touched:Connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) local leaderstats = player:WaitForChild("leaderstats") local Cash = leaderstats.Cash local Rebirths = leaderstats.Rebirths local Gems = leaderstats.Gems local AmountToMultiply = 50 if Rebirths.Value == 1 then Cash.Value = Cash.Value + AmountToMultiply * 2 Gems.Value = Gems.Value + Rebirths.Value elseif Rebirths.Value > 1 then Cash.Value = Cash.Value + AmountToMultiply * Rebirths.Value Gems.Value = Gems.Value + Rebirths.Value elseif Rebirths.Value <= 0 then Cash.Value = Cash.Value + AmountToMultiply end player.Character:SetPrimaryPartCFrame(CFrame.new(script.Parent.Parent.TeleportPart.Position)) end)