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

How do I transfer an intvalue of something to leaderstats values?

Asked by 7 years ago
local money = script.Parent:WaitForChild("money").Value
function payout(plr)
    local plrname = (plr.Name)--this is for later when the tycoon gets the name from the owner door
    local srvrmoney = game.Players[plrname]:FindFirstChild(leaderstats.money.Value)--might have to be changed to waitforchild idk yet
    if plr.Name == "macabe55101" then
        srvrmoney = money
    end
end

game.workspace.moneygiver.Touched:connect(payout)

this is the best I have so far I think I messed up with the syntax needed on line 1... Im trying to transfer the value of a intvalue to another in a player in leaderstats once the game is run.

0
also line 5 will be changed to be whichever player owns the tycoon, but that's besides the point macabe55101 38 — 7y
0
define 'money' inside the function. Otherwise it will be the same number everytime. Goulstem 8144 — 7y
0
money is a intvalue place holder macabe55101 38 — 7y
0
bump plez halp sermone macabe55101 38 — 7y
View all comments (2 more)
0
Maybe it has something to do with srvrmoney. srvrmoney is the value of the money and when you are changing it later on in the function it is changing the variable value and not the IntValue Value RGRage 45 — 7y
0
Correct me if i'm wrong... RGRage 45 — 7y

1 answer

Log in to vote
0
Answered by
RGRage 45
7 years ago

Value has not been used correctly:

local money = script.Parent:WaitForChild('money') -- Using the value of the object will get the value for one time only, so use the object and get the value later

function payout(hit) -- Change plr to hit because this function is being called by a touched event, hit is the part that is being hit

    if hit.Parent:FindFirstChild('Humanoid') then -- If there is a humanoid then hit's parent is more likely to be a player

        local plr = game.Players:GetPlayerFromCharacter(hit.Parent)

        if plr ~= nil then -- checks to see if it is actually a player

            local plrname = (plr.Name) -- plr's Name

            if plrname == 'macabe55101' then
                local srvrmoney = plrl:FindFirstChild('leaderstats').money --This is the object for srvrmoney

                srvrmoney.Value = money.Value -- Use value when calculating numbers with the value

            end
        end 
    end
end)

game.Workspace.moneygiver.Touched:connect(payout)

If I am wrong please correct me, but if I helped please accept.

0
"~= nil" on line 9 of your code isn't necessary, as the "if" statement will return true if the values presented to it are equal, or true. TheeDeathCaster 2368 — 7y
0
@TheAlphaStigma, Thanks I'll keep that in mind. RGRage 45 — 7y
Ad

Answer this question