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

My Sell Area Wont Sell My Items For My Currency Why?

Asked by
zpfran -25
5 years ago
Edited 5 years ago

The script is supposed to detect when the player touches the brick or part that is inside the sell and if the players has more than 1 duck or item than it will sell depending on the rebirth amount, then the item amount should go back to 0 and you get your cash.

local Part = script.Parent
Part.Touched:Connect(function(HIT)
    local H = HIT.Parent:FindFirstChild("Humanoid") 
    if H then
        local player = game.Player.LocalPlayer  
if player then
    local leaderstats = player:WaitForChild("leaderstats")
    local Currency = leaderstats:FindFirstChild("Cash").Value
    local Selling = leaderstats:FindFirstChild("Ducks").Value
        if Selling.Value > 0 then
            Currency.Value = Currency.Value + Selling.Value * 1 * leaderstats.Rebirths.Value + 1
            Selling.Value = 0
        end
end
end
end)
0
Use a code block and explain what the script is suppose to do or we can't help. raid6n 2196 — 5y
0
ok zpfran -25 — 5y
0
help zpfran -25 — 5y
0
I helped TheRealPotatoChips 793 — 5y

1 answer

Log in to vote
2
Answered by 5 years ago

So at line 8 and 9, you wrote that the variables currency and selling are the VALUES of the intvalues in leaderstats. Then, at line 10, 11 and 12, you wrote the variables, but you added a ".Value" at the end of each variable.

Also, at line 11, you did the selling value x the rebirth value. Altough, if the player has 0 rebirths, it will multiply it by 0 and every number multiplied by 0 equals 0. I see you did Rebirth.value + 1, but the code will run the multiplications and the divisions FIRST, then the additions and substractions.

Also, you are obligated to put this code in a script and not in a localscript cuz localscripts can't detect Touching. However, at line 5, you wrote game.Players.LocalPlayers and game.Players.LocalPlayers can only be runned in a localscript. What I suggest is to do:

local Part = script.Parent
Part.Touched:Connect(function(HIT)
    local H = HIT.Parent:FindFirstChild("Humanoid")
    if H then
        local player = game.Players:WaitForChild(HIT.Parent.Name)
        if player then
            local leaderstats = player:WaitForChild("leaderstats")
            local currency = leaderstats.Cash
            local selling = leaderstats.Ducks
            if selling.Value > 0 then
                Currency.Value = Currency.Value + Selling.Value * 1 * (leaderstats.Rebirth.Value +1)
            end
        end
    end
end)

So I've changed the variables currency and selling and I added brackets to the Rebirth's Value so it will add 1 to it before multiplicating with the player's Ducks's Value. Also, I've changed the variable player because it could not work in a script. I got the name of the parent of HIT, so the player's character's name, then I got it in the game.Players, because the player's character's name is the same as the player's name in game.Players.

I really hope this helped!

0
THANKS!!! zpfran -25 — 5y
0
no problem! TheRealPotatoChips 793 — 5y
Ad

Answer this question