Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

6 comments

0

also line 5 will be changed to be whichever player owns the tycoon, but that's besides the point

0

define 'money' inside the function. Otherwise it will be the same number everytime.

0

money is a intvalue place holder

0

bump plez halp sermone

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

0

Correct me if i'm wrong...

1 answer

✓ Accepted answer

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.

2 comments

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.

0

@TheAlphaStigma, Thanks I'll keep that in mind.

This discussion is preserved as it was. New answers, comments, and votes are closed.