Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

why isnt my rebirth script not working when i touch the part?

Asked by
hot_spi 20
4 years ago

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?

0
idk maybe try changing *else* with *elseif* FurryPapal 90 — 4y
0
Before your if-statement, please try print(Rebirths.Value). It is possible that you are not incrementing the Rebirths correctly elsewhere and that it is 0 by the time you run this script. Sparks 534 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)
0
but like when the rebirth value is 1 it will be 50 * 1, which didnt do anything. hot_spi 20 — 4y
0
and also the gems hot_spi 20 — 4y
0
I edited it WoGiTeam 60 — 4y
Ad

Answer this question