Hi,
I’m working on a drop system and i have it completed now I’m trying to figure out how i could make a player type in a number in a textbox and that number being the amount of how many cash it drops.
Thanks in advance!
Hi,
I’m working on a drop system and i have it completed now I’m trying to figure out how i could make a player type in a number in a textbox and that number being the amount of how many cash it drops.
Thanks in advance!
This has nothing to do with your post. But instead of ‘wait’ use ‘task.wait’. Task.wait is more efficient and reliable than ‘wait’
First:
You need a button and a textbox.
Add this local script to the button
local button = script.Parent
local Box = button.TextBox
local event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
button.Activated:Connect(function()
if tonumber(box.text) then
event:FireServer(math.round(tonumber(box.Text)))
end)
Then make a server script
local event = game:GetService("ReplicatedStorage").RemoteEvent
event.OnServerEvent:Connect(function(player,amount)
--your code here.
--"amount" is the custom amount that the player entered and it will be a number
end)
Is there any way i could make it change this IntValue?
Once it’s fired to the server using the above method with remotes, you can simply change the value of it from the server.
GrabReward.Value = amount
would suffice as you’ve already converted the entered string to a number on the client side.
It doesn’t seem to be working but i don’t know why
Could you possibly showcase the entirety of your new script? It would help me understand the current issue!
Please copy and paste your code. It’s hard for anyone to help when you send screenshots of your code.
Server script:
game.ReplicatedStorage.DCBEvent.OnServerEvent:Connect(function(player, amount)
local part = game.ServerStorage:FindFirstChild("BagOfDogeCoins"):Clone()
part.Parent = workspace
part.CFrame = player.Character.HumanoidRootPart.CFrame
game.ServerStorage:GetChildren("BagOfDogeCoins").GrabReward.Value = amount
end)
Button Script:
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.DCBEvent:FireServer()
end)
local box = script.Parent.Parent.TextBox
script.Parent.Activated:Connect(function()
if tonumber(box.Text) then
game.ReplicatedStorage.DCBEvent:FireServer(math.round(tonumber(box.Text)))
end
end)
Replace this line:
game.ServerStorage:GetChildren("BagOfDogeCoint").GrabReward.Value = amount
with this:
part.GrabReward.Value = amount
You’re trying to change the value of the recently cloned bag correct? Instead of changing the value from ServerStorage, try the following instead:
part.GrabReward.Value = amount
This works now, thank you. I see that the IntValue has changed but it still gives me 250 (which) is the default set in serverstorage.
local prompt = script.Parent.Grab
local bag = script.Parent
local amount = script.Parent.GrabReward.Value
prompt.Triggered:Connect(function(player)
player.leaderstats.DogeCoins.Value = player.leaderstats.DogeCoins.Value + amount
prompt:Destroy()
bag.Transparency = 1
script.Parent.EarnedDC.Enabled = true
wait(2)
bag:Destroy()
end)
I believe this may be because you’re referencing it too early. For example, “amount” here is most likely 250 regardless of whatever the value is, because the script has run before.
Instead, you could simply do the following and it should work fine:
local amount = script.Parent.GrabReward
-- then when you're ready to give points:
player.leaderstats.DogeCoins.Value = player.leaderstats.DogeCoins.Value + amount.Value
-- also incase you didn't know, you could always do the following if you wanted to, although it doesn't really matter!
player.leaderstats.DogeCoins.Value += amount.Value
This works! One slight problem I’m having now is that for some reason 2 bags spawn, one with 0 value and one with the value i typed in.
Nevermind, i managed to fix this.
Thank you for the help! Are you ok with me marking the original reply from black1shadow1048 as solution?
Feel free to mark whichever post helped you the most as the solution as a general rule of thumb, I’m just happy your system is working now! Best of luck with your project
Alright. Thank you so much for the help!