HOW TO MAKE A PART GIVE YOU CURRENCY 🛠️ Roblox Studio Tutorial
HTML-код
- Опубликовано: 8 сен 2024
- In todays video I show you how to make a Part or a Item give you currency (Cash or Coins) when the item is touched, this script includes a data store, meaning if a player leaves the game the data saves and when they rejoin they will have the same amount of currency before they left. I Hope you enjoyed the video, Have a lovely rest of your day!
If you are a bit confused what to do, Feel free to message me on Discord and Ill help you out!
🌟 Floppys Discord Server: / discord
Script 1 (Leaderstats Script) :
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Coin = Instance.new("IntValue")
Coin.Name = "Coins" -- Change this to what you want the leaderstat name to be
Coin.Value = 0
Coin.Parent = leaderstats
end)
Script 2 (Coin Script) :
local DataStoreService = game:GetService("DataStoreService")
local CoinsDataStore = DataStoreService:GetDataStore("CoinsDataStore")
local RespawnTime = 5 -- Change the number to adjust how often you want the coin to respawn
function savePlayerData(player)
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local coins = leaderstats:FindFirstChild("Coins")
if coins then
CoinsDataStore:SetAsync(player.UserId .. "_Coins", coins.Value)
end
end
end
function loadPlayerData(player)
local success, result = pcall(function()
return CoinsDataStore:GetAsync(player.UserId .. "_Coins")
end)
if success and result ~= nil then
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local coins = leaderstats:FindFirstChild("Coins")
if coins then
coins.Value = result
end
end
end
end
function onTouch(otherPart)
local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
if player then
local leaderstats = player:FindFirstChild("leaderstats")
if not leaderstats then
return
end
local coins = leaderstats:FindFirstChild("Coins")
if coins then
coins.Value = coins.Value + 1 -- Change the +1 to how much currency you want that coin to give
end
script.Parent.CanTouch = false
script.Parent.Transparency = 1
wait(RespawnTime)
script.Parent.CanTouch = true
script.Parent.Transparency = 0
end
end
function onPlayerRemoving(player)
savePlayerData(player)
end
function onPlayerAdded(player)
loadPlayerData(player)
end
script.Parent.Touched:Connect(onTouch)
game.Players.PlayerRemoving:Connect(onPlayerRemoving)
game.Players.PlayerAdded:Connect(onPlayerAdded)
🌟 Floppys Roblox Game : www.roblox.com....
Roblox Studio Tutorial
Roblox Studio
Studio Tutorials
Floppy just needs 5 mins and everything is good❤
Shouldn't we change this:
leaderstats:FindFirstChild("Coins")
in case that we set different name in first script?
Yes if you have your name of the currency for example as Cash the change coins to cash
THANK YOU SOOOO MUCH! it helped me a lot!
tysm floppy you are really smart cuz you create scipts like so long i really like your videos and you really help me out on making my new game
tysm ive been looking for this for ages bro
thank soo much it actually worked
Floppy Always Makes Great Tutorials And Also Great Tips On Developing! Props To Floppy!
Tysm, I've been trying to save leaderstats for days now with none of the tutorials working but yours worked! Thank you!
Thanks you so much it works perfectly! Amazing tutorial! Thanks so much!
You are one of the only tuturial RUclipsrs where the code works
Try gamer M8
His scripts work
@@KennettHolidays try any youtuber 99.99% of them work
I had to rewatch this 4 times to get it right, but i did it! thank you so much much Floppy! :)
Make a claimable flag that gives you curency while having it claimed.
Hey, nice vid! Could you do a variant where you use a proximity prompt to get the cash ?
Thank you!
its been a year and this still helps so much!
my coin just wont spawn when i start the game im doing what he said tho
@@Nameismonkey i also have a problem, my stats in my leaderboard don't go up when i collect the item
@@dilsan78 for me the, amount that the coins go up with is random although i set it to +1
@@drizzty6802 thats also what happens to me
@@remaxplays I recommend u check out his "how to make a coin system" video that works way better, atleast for me
QUESTION: It's giving me random values for the coins ranging from 1-15, from what I've seen at least. How would I go about making that range 1-5 for the coin value? I just don't want people to be able to progress so fast if one coin = 15.
Your respawn time is too fast and multiple coins are stacking values inside each other
@Luke-qr5kt mines at 60 tho and it's doing that
thank you floppy i understand now
Im making my first simulator and this tutorial really helped. Thanks!
thanks im making a turtle jumb game and this helped very much
floppy can you make a video about a shop system that we can use coins to buy stuff
TYSM!!! i tryi9ed it the first time didn't work the next time not working cuz smt wasn't working right and then the third time it worked so ty
mine kinda broke where for some reason it added 10 or 2 sometimes but I realized its actually better for area 1 as I made the goal 100 coins
same
Shouldn't we make the savesystem in a script apart from this?
Ty so much this really helped makeing an horror game
is it okay if you can make a tutorial on how to use these coins to buy stuff from a shop? Love the tutorial and keep on grinding!
ye he's right
Flopy tysm for all ur videos they all help but can u make the egg that u can buy with coins
no
i don't know how to make it work i want to change the name on the leaderboard to protons but when i change everything it doesnt work it doesnt even go away or reapear hellp mee please
mine tooo
u have to change the name (anywhere it says coins in the script) also dont add decals to ur part
THANK YOU SOOO MUCH about the thing is I get 7 coins if I collect it -
What if we have 2 types of currency
Thanks you so much
who knows how to set the timer so that it disappears after the player touches the coin, because when I stand directly on it, I get 4 instead of 1, maybe it's because it disappears for a very long time?
THANK YOU SO MUCH IM MAKING A GAME CALLED SUPER NOOB WORLD AND I REALLY NEEDED THIS
Oh my god, your the same with the shop tutorial ..... I'm trying to make a game like lethal company. Thank you.
im using this for my obby simulator game that i will submit for a stream
THANK YOU SO MUCH BROOOO !!!!
THANK YOU SO MUCH!!!😀😀😀😀
this is such a good tutorial
Hi floppy can you please make a item shop video where you can make a shop and you can buy stuff with your coins
Can u make tutorial on how to make a shop where you buy stuff with the coins? Thanks love your channel
ty that helpd me so much 😁
guys if it doesent work for the collecting script Here is a script i made it 100% WORKS!!
local db = true
script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") ~= nil then
if db == true then
db = false
script.Parent.Transparency = 1
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1
script.Sound:Play()
script.Parent.Transparency = 1
wait(1)
db = true
script.Parent.Transparency = 0
end
end
end)
idk why but it doesnt work im i doing something wrong
now it works for me tysm
Ty so much this is working great keep up what you are doing
you forgot to make a spawn limit so the coins spawn on top of each other making it so when the sever is on for a long time you can get like 500 coins
Can you please make a tutorial on how to make your coins show on a UI ? And how to exchange coins for items ?
Someone should make a several part tutorial on how to make a full currency systems
Tysm for me it worked! 😊
i love your vidos so much ty
TYSM. it worked for me :D
It works fine except for the fact that I set it to 10 coins but it gave me 20 once, then 150 the next time I touched it. Is this because the game thinks I touched it multiple times or what.
yeah wait I got you so here is the script where it gives only like 1 coins
local debounce = false
function onTouch(otherPart)
local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
if player and not debounce then
debounce = true
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local coins = leaderstats:FindFirstChild("Coins")
if coins then
coins.Value = coins.Value + 1 -- Change the +1 to how much currency you want that coin to give
end
end
script.Parent.CanTouch = false
script.Parent.Transparency = 1
wait(5) -- this makes it how much you have to wait for the coin to respawn after getting it
script.Parent.CanTouch = true
script.Parent.Transparency = 0
debounce = false
end
end
script.Parent.Touched:Connect(onTouch)
and also if you want the coin to spin:
local TurningSpeed = 10 -- You can change how fast you want the part to spin here
while true do
script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(0, math.rad(TurningSpeed), 0)
wait(0.01) -- This determines how often the part turns (Updates the part to turn every 0.01 seconds, The lower the number the better transition)
end
same
OMG! that helps lot!! thank you!! keep doing more stuff like these, i'm working on simulator games
Im working on a simulator too
same here!
Same here
Just shows that simulators are going to overlap roblox evebtually
@@RealRyan614same
tysm for the tutorial
Best tutorial crator!❤❤
It won’t spawn:(
yea me too
I will always come to you for roblox help
Thanks so much!
ty now i can continue editing my game
hey floppy been trying to find a tutorial for how to make people buy stuff with the currency but i can't find any so i saw this tutorial on how to make in game currency and i think it would be a good idea for you to make this
Thx so much broz!
tysm i needed that for my kaiju game can you next do a how to make a atomic breath attack for godzilla
it actually worked lo ill make a game called cookie simulator idk if it already exists but its fine lol
Mine is giving random numbers, sometimes it'll give 9, and next it'll give me 6000, any ideas?
again,another tutorial what doesn't work for me here's error: DataStore can't be accessed from client
Hey Floppy, Good video and Thank you!, but how we can make a GUI working with that?
im trying to make my first simulator but the value is messed up. The value on the script says 1 but it gives 4, 7, 2, 6, 1, etc. it wont give me a consistent value
Same.
DO YOU WANNA FIGHT ME oh shit they’re dead… DO YOU WANNA HIDE A BODY
Hey! Could you help me with the code by addng like a pickup sound when you touch it? I really want that, but i don't know how to do it.
TYSM!
Anyone know what im doing wrong?,
when i test the game and go to my item everything works perfectly fine but i don't get any currency in the leaderboard
Whenever i collect it, it does disappear but does not add cash to my game.
Hey floppy do you mind making a tutorial where I can use this currency to get certain tools? Like a shop? thanks!
Maybe im a little late to comment, but i would ask if you could make a shop for things to buy via those coins😊
tyyyyy soooo muchhhh
hey floppy can you make a video about a medieval shop that uses this currency?
I can only claim a coin once ??? How do I fix
Changing the respawn time
some times it gives me more then one value. I got 3 or 2 sometimes. its rare for all parts to give me 1 value
I have fixed that issue here is the full updated code for that.
local DataStoreService = game:GetService("DataStoreService")
local CoinsDataStore = DataStoreService:GetDataStore("CoinsDataStore")
local RespawnTime = 2 -- Change the number to adjust how often you want the coin to respawn
local isTouching = false
function savePlayerData(player)
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local coins = leaderstats:FindFirstChild("Coins")
if coins then
CoinsDataStore:SetAsync(player.UserId .. "_Coins", coins.Value)
end
end
end
function onTouch(otherPart)
if isTouching then
return
end
isTouching = true
local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
if player then
local leaderstats = player:FindFirstChild("leaderstats")
if not leaderstats then
isTouching = false
return
end
local coins = leaderstats:FindFirstChild("Coins")
if coins then
coins.Value = coins.Value + 1 -- Change the +1 to how much currency you want that coin to give
end
script.Parent.CanTouch = false
script.Parent.Transparency = 1
wait(RespawnTime)
script.Parent.CanTouch = true
script.Parent.Transparency = 0
end
isTouching = false
end
function loadPlayerData(player)
local success, result = pcall(function()
return CoinsDataStore:GetAsync(player.UserId .. "_Coins")
end)
if success and result ~= nil then
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local coins = leaderstats:FindFirstChild("Coins")
if coins then
coins.Value = result
end
end
end
end
function onPlayerRemoving(player)
savePlayerData(player)
end
function onPlayerAdded(player)
loadPlayerData(player)
end
script.Parent.Touched:Connect(onTouch)
game.Players.PlayerRemoving:Connect(onPlayerRemoving)
game.Players.PlayerAdded:Connect(onPlayerAdded)
if you change the name of the currency, do you change the name of "coin" every instance it shows up?
Hey great tutorial i was just wondering how to change the name of the currency in script 2??
i got a problem beacuse coins give diffrent value like 1 and 2 and i seted it to give 1 value
it kinda doesn't work cause I have decals on my part 😭😭
(not and error with ur code or anything)
Simply make it so the decals get transparency to 1 when touched
@@Moij56-Games OMGGG!!! IDK IF IT WORKS BUT TYSM!!! ❤️ ❤️
Yo so I made a pathfinding dummy thats meant to obtain coins for you
Is there anyway to make it so if a certain Npc Touches the coin the Player obtains it?
It doesnt save when you rejoin the game
Hi, Sorry about this. Please create a ticket in my discord server and we can help you out!
2 months late probably but, to make currency save, you must create a data store script
hello floppy i wanted to ask how can i make the money i collect add to my gui instead of the leaderboard
great tutorial! but i would like that the way to get money is to kill zombies, can you do that for me?
sorry it didn't work when i tried to collect it didn't give the money and i put the leader stat script for the leaderstat gui that shows leaderstats and it don't work. Sorry but thanks! Your other videos are super helpful!
Please Answer, How do i make it give me the amount once, not every single time you step on it.
when i touch the part, i get anywhere from 3 to 10 coins, pls help
You're probably not going to see this, but can you make a tutorial so that you earn money everytime a player kills someone?
It doesn't work I can walk thought it but the coin doesn't add
Mine aren't disappearing when collected, what did I do wrong?
Nevermind there was just a decal on my coin object
I have the same problem. What is a Decal?
Can you make a version of The 2nd Script but replaced with Cash
Just replace the line of code: leaderstats:FindFirstChild("Coins") with leaderstats:FindFirstChild("Cash"), or whatever you want to call your currency
omggggggggggggggggg TYSM!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Its not working. Its giving me 1-5 coins randomly. pls someone tell mehow to fix it
hey, this tutorial is nice, but i want to make it so that the coin only disappears for the player who is collecting it, can you make a video about that?
how do you make it not despawn when you touch it? btw TYSM for this tutorial
remove the 4 lines starting with "script.Parent" in "onTouch" function
I can get it to work but after I get it once it won’t let me claim it again any help ??
how do u make it give u coins if u shoot a basketball and it goes in?
when i cliam it it disseapers but it doesnt go to lb stat
Nice video, But can you make one work with GUI please. 😃
What if i made a gem model in blender and did everythink but on the properties nothing shows up about can colide
How do you make it so it makes a number on a gui go up?
but what if your making a pet sim likely and you want them to smash it what do you then do hope you can make a vid abt that
its working but not when i duplicate the coin
probably cuz its bugged of duplicated name. try to make something like Coin1, coin2, etc..
How can I make a sound play when I collect the coin?
This is the tutorial for you!
ruclips.net/video/G9C5Ae2yLcw/видео.html