It always keeps saying ,Player doesn’t exist in the game!" also he is existing and the amount ~= nil, why is that?
Local script:
local player = game.Players.LocalPlayer
local input = script.Parent.Parent.TextBox.Text
local input2 = script.Parent.Parent.AmountBox.Text
script.Parent.MouseButton1Click:Connect(function()
if game.Players:FindFirstChild(input) and input2 ~= "" then
game.ReplicatedStorage.Transfer:FireServer(input,input2)
else
script.Parent.Text = "Player doesn't exist in the game!"
wait(3)
script.Parent.Text = "Give Money"
end
end)
Server Script:
game.ReplicatedStorage.Transfer.OnServerEvent:Connect(function(player,input,input2)
if tonumber(input2) then
if input2 <= player.leaderstats.Cash.Value then
player.leaderstats.Cash.Value -= input2
input.leaderstats.Cash.Value += input2
end
end
end)
It says that because you already declared the “input” variable when the script started and not when the button is clicked. (so it always check the same variable)
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
local input = script.Parent.Parent.TextBox.Text
local input2 = script.Parent.Parent.AmountBox.Text
if game.Players:FindFirstChild(input) and input2 ~= "" then
game.ReplicatedStorage.Transfer:FireServer(input,input2)
else
script.Parent.Text = "Player doesn't exist in the game!"
wait(3)
script.Parent.Text = "Give Money"
end
end)
Also make sure to tell players that the target player’s name is cap-sensitive.
if tonumber(input2) then
if tonumber(input2) <= player.leaderstats.Cash.Value then
You only checked if it was number, but you didn’t make it number to compare to the leaderstats value, but instead a string (which is why you got that error).