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

How to use variable instead of playername?

So, it sounds bit complitcated, but it isn't. What I am trying to do is make coin giver which, probably will work fine but I found out I cant get this one problem solved, I created local which is located to TextBox (You type in the players name you want to give the icon to) and put the name of the local in the coin giving thingy, check script lower.

function start()
	local input = script.Parent.Parent.Input.Text
	game.Players.input.leaderstats.Coins.Value = game.Players.input.leaderstats.Coins.Value +5
end

script.Parent.MouseButton1Click:connect(start)

Unfortunately, this don't work, any ideas how to fix this?

2 comments

0

Wdym?

0

Read it again, the you put input in txt box, local input = etc. is where the textbox is located with the text in it, then i tried to apply the local input in game.Players.input - the input whats in the text box

1 answer

✓ Accepted answer

It's quite simple to do this, all it takes is simple math:

local amountToGive = script.Parent.amount --TextBox where the player puts the amount of cash to give
local playerName = script.Parent.player --TextBox where the player types another players' name
local submit = script.Parent.submit --TextButton used to submit form to donate cash to player
submit.MouseButton1Click:Connect(function() --When clicked
	local playerToGive = game:GetService("Players"):FindFirstChild(playerName.Text) --Player who receives donation
	local playerWhoClicked = game.Players.LocalPlayer --Player who wants to donate
	if playerToGive then --If the player we typed in is actually there
		if playerWhoClicked.leaderstats.Cash.Value >= amountToGive.Text then --If the player who wants to donate has enough cash 
		playerToGive.leaderstats.Cash.Value = playerToGive.leaderstats.Cash.Value + amountToGive.Text --Give cash to player
		playerWhoClicked.leaderstats.Cash.Value = playerWhoClicked.leaderstats.Cash.Value - amountToGive.Text --Subtracts the cash from the player who donated
		end
	end
end)

Just make sure this is in a LocalScript so LocalPlayer can be indexed! Hierarchy here. Please accept my answer if this helped!

2 comments

0

Thanks !

0

No problem

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