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

I want to give a specified player a specified amount of currency, how can I fix my script to do so?

I'm trying to make 2 scripts for a GUI that when I type a player's name in the Username box and an amount of money in the Amount box it gives them that amount of my currency, called Shards (My game is in the testing stages and I don't want all of my testers to grind through a game that would normally take hours to beat).

How can I make it work? (I'm not an expert in scripting, but I'm not a novice)

Local Script

local mf = script.Parent
local f = mf.Frame
local plr = game.Players.LocalPlayer
local u = f.Username.Text
local a = f.Amount.Text
local c = f.Click


c.MouseButton1Click:Connect(function(plr)
	game.ReplicatedStorage.SecondaryEvents.Hidden.NormalEvent:FireServer(plr,u,a)
end)

ServerScript

game.ReplicatedStorage.SecondaryEvents.Hidden.NormalEvent.OnServerEvent:Connect(function(plr,u,a)
	if plr.Name == "Bearturnedhuman" or "Timewizard16" then
		local su = u
		local sa = a
		if game.Players:FindFirstChild(su) then
			local ou = game.Players:FindFirstChild(u)
			ou.hiddenstats.Shards.Value = ou.hiddenstats.Shards.Value + sa
		end
	end
end)

2 comments

0

Ok, I just made another answer. Try that :D

0

I've tested everything, and it works. If it still doesn't work, I'll make a model of the one i made and send it to you

1 answer

✓ Accepted answer

Ok fixed it completely. Firstly, you had set variables u, and a to the text right off the bat. Next, you tried adding a string onto an IntValue. To fix this, we used 'tonumber', a function used to convert strings to numbers --if possible

ServerScript

local replicatedstorage = game:GetService("ReplicatedStorage")
local events =  replicatedstorage:WaitForChild("SecondaryEvents")
local hiddenevents = events:WaitForChild("Hidden")
local normalevent = hiddenevents:WaitForChild("NormalEvent")


normalevent.OnServerEvent:Connect(function(plr, u, a)
    if plr.Name == "Bearturnedhuman" or plr.Name == "Timewizard16" then
        local su = u
        local sa = a
        if game.Players:FindFirstChild(su) then
            local ou = game.Players:FindFirstChild(u)
            ou.hiddenstats.Shards.Value = ou.hiddenstats.Shards.Value + tonumber(sa)
        end
    end
end)

LocalScript

local mf = script.Parent
local f = mf:WaitForChild("Frame")
local plr = game.Players.LocalPlayer
local u = f:WaitForChild("Username")
local a = f:WaitForChild("Amount")
local c = f:WaitForChild("Click")

local replicatedstorage = game:GetService("ReplicatedStorage")
local events =  replicatedstorage:WaitForChild("SecondaryEvents")
local hiddenevents = events:WaitForChild("Hidden")

local normalevent = hiddenevents:WaitForChild("NormalEvent")

c.MouseButton1Click:Connect(function(plr)
	normalevent:FireServer(u.Text,a.Text)
end)

2 comments

0

Thank you so much!! I was working on this for literal hours, and it finally works!

0

I had to go into studio to see all the problems. Glad I could help :)

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