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

How to use variable instead of playername?

Asked by 6 years ago
Edited 6 years ago

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?

0
Wdym? hiimgoodpack 2009 — 6y
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 ItzBlazik 9 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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!

0
Thanks ! ItzBlazik 9 — 6y
0
No problem PyccknnXakep 1225 — 6y
Ad

Answer this question