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

My ores are not adding money to the leaderboard?

Asked by
tjtorin 172
7 years ago
plr = game.Players.LocalPlayer
worth = game.Players.plr.leaderstats.Money.Value 
function destroy(hit) --'hit' parameter is now the part that touched!
    if hit.Name == "drop" then --Check the hit's name.
        worth = worth+10
        hit:Destroy()
    end
end

--workspace.drop.Touched:connect(destroy)
script.Parent.Touched:connect(destroy)

Im not sure why this does not add 10 when it hits the furnace

5 answers

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

When you set a variable to a ValueObject's Value property, that variable becomes equivalent to what the Value was when the script executed that line of code.

By changing the variable, you are simply changing the variable. The ValueObject's value is not affected.

You need to reference the object from the variable, and index the property to set it.


Now, secondly, you are getting the Player incorrectly. Since this is a server script you cannot use game.Players.LocalPlayer. You need to get the player some other way. That way is up to you. Preferably by an 'owner' StringValue to the tycoon.

local plr --This is the player.
local worth = plr:WaitForChild("leaderstats"):WaitForChild("Money")

function destroy(hit)
    if hit.Name == "drop" then
        worth.Value = worth.Value + 10
        hit:Destroy()
    end
end

script.Parent.Touched:connect(destroy)
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

I'm just gonna fix this, upvote and accept answer if worked

In a local script;

local player = game.Players.LocalPlayer
local Value = 10 -- the value of the ore
local curreny = player:WaitForChild("leaderstats").Money.Value
local Furnace = script.Parent --The furnace
local Cashed = false --make debounce so the player doesn't get a lot of 10 money

Furnace.Touched:connect(function(Hit)
    wait() --Dunno why
    if Hit.Parent.Name == "Drop" then
        Cashed = true
        wait() -- Dunno why
        currency = currency + Value
        Hit.Parent:Destroy()
        wait() -- Dunno why
        Cashed = false
        if Cashed then return end -- We don't want the player to get too much money
    end
end)

Try, comment, ask and explain.

0
Explain the reason behind your answer plz. Thanx. c; TheeDeathCaster 2368 — 7y
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Don't use a LocalScript!

LocalScripts don't work in workspace unless they're in a player character. Also, if FE was enabled, the local scripts would only affect the value locally, which you obviously don't want!

The next problem is you need to get the player. But which player? That's something you need to figure out, but I'll provide an example. By touching the ownerBrick, you become the owner of this tycoon.

local owner

local debounce = false
local function destroy(hit)
    if owner and not debounce and hit.Name == "drop" then
        debounce = true
        local worth = owner.leaderstats.Money
        worth.Value = worth.Value+10
        hit:Destroy()
        wait(.5)
        debounce = false
    end
end
script.Parent.Touched:Connect(destroy)

local ownerBrick = script.Parent.Parent:WaitForChild("OwnerBrick")
ownerBrick.Touched:Connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if((plr)and(not owner))then
        owner = plr
    end
end)

game.Players.PlayerRemoving:Connect(function(plr)
    if(plr ==  owner)then
        owner = nil
    end
end)
Log in to vote
0
Answered by
RootEntry 111
7 years ago

This is the solution. You need to have the .value after the 'worth' value. Then it will work.

local plr --This is the player.
local worth = plr:WaitForChild("leaderstats"):WaitForChild("Money")

function destroy(hit)
    if hit.Name == "drop" then
        worth.Value = worth.Value + 10
        hit:Destroy()
    end
end

script.Parent.Touched:connect(destroy)
Log in to vote
-3
Answered by
xVanc -1
7 years ago
Edited 7 years ago

ok so there are many errors but idk if i can completely solve ur error. i will make a few changes though.

[UPDATE!]: now that i know ur problem.. ill try again.

SCRIPT.

in that item(part) make a group then add a humanoid inside the group. then add this script inside the part.

it should look like this.

GROUP>(Humanoid, OrePart).OrePart>Script>(inside the script below)

function onTouched(part)
    local ore = script.Parent
    local h = part.Parent:findFirstChild("Humanoid")
    if (h~=nil) then
        local thisplr = game.Players:findFirstChild(h.Parent.Name)
        if (thisplr~=nil) then
            local stats = thisplr:findFirstChild("leaderstats")
            if (stats~=nil) then
                local score = stats:findFirstChild("Money")-- change this to what the thing is like Money or Points
                if (score~=nil) then
                    score.Value = score.Value + 10 -- change this to the number of cash they get
                end
                ore:Destroy()
            end
        end
    end

end

script.Parent.Touched:connect(onTouched)

MY FINAL ANSWER, HOPE IT WORKS.

0
If you're unsure of how to actually fix, don't bother answering:P Goulstem 8144 — 7y
0
i love to try, it's how i learn. xVanc -1 — 7y
0
Great for you, unfortunately for others it's not as enlightening - just an inaccurate solution. Goulstem 8144 — 7y
0
if it's a right answer then i feel more happy, and i learn more and i progress that way xVanc -1 — 7y
0
Explain the reason behind your answer plz. Thanx. c; TheeDeathCaster 2368 — 7y

Answer this question