I need help with a script
PROBLEM: I’m trying to figure out how to make it where when you kill another person you will get coins and with those coins you can get something from the shop.
I have it where you kill someone and you’ll get coins but i don’t no how to get it where you can save the coins and spend them in the shop.
1 Like
To save the coin across different sessions you need datastores
Use Datastores to save the coins/cash
i new that but i have no idea how
its clearly teaches you how to do in youtube vids and also the developer.roblox.com
the problem is none of the youtube vids help they all dont work
can you give the current script you have so i can help you edit to make it saveable
I suggest you learn Datastore2, its easy to understand and it can prevent from data lost
here is the link if u want to learn it
(81) Roblox DataStore2 Tutorial - ADVANCED DEVELOPERS ONLY (NOT NORMAL DATASTORE) - YouTube
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new(“Folder”,player)
folder.Name = “leaderstats”
local currency1 = Instance.new(“IntValue”)
currency1.Name = “Money”
currency1.Parent = folder
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:Connect(function()
local tag = character.Humanoid:FindFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
currency1.Value = currency1.Value + 10
end
end
end)
end)
end)
Could I see a script you currently have?
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new(“Folder”,player)
folder.Name = “leaderstats”
local currency1 = Instance.new(“IntValue”)
currency1.Name = “Money”
currency1.Parent = folder
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:Connect(function()
local tag = character.Humanoid:FindFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
currency1.Value = currency1.Value + 10
end
end
end)
end)
end)
Could you redo this? Not all of it is in a script format.
local Datastore=game:GetService('DatastoreService'):GetDataStore('PlayerData')
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new(“Folder”,player)
folder.Name = “leaderstats”
local currency1 = Instance.new(“IntValue”)
currency1.Name = “Money”
currency1.Parent = folder
currency1.Value= Datastore:GetAsync(player.UserId) or 0
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:Connect(function()
local tag = character.Humanoid:FindFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
currency1.Value = currency1.Value + 10
end
end
end)
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
Datastore:SetAsync(plr.UserId,player.leaderstats.Money.Value)
end)
game:BindToClose(function()
wait(5)
end)
im sorry if it had error cuz im on mobile
where do i put this under or do i add it to my current ?
just replace the current with this
ok. Do i hafto put anything under Replicated Storage
Using :BindToClose
to just run wait(5)
does nothing. You would want to put your actual saving code here. Also, when replying actually format your code. Your code is super sloppy right now.
can someone help me with this pls
Yes, I would love to help you. Could you send your code to me where it is all formatted? Then I will walk you through this.
ok thank you so much! this ia my code and its all under ServerScriptService
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new(“Folder”,player)
folder.Name = “leaderstats”
local currency1 = Instance.new(“IntValue”)
currency1.Name = “Money”
currency1.Parent = folder
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:Connect(function()
local tag = character.Humanoid:FindFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
currency1.Value = currency1.Value + 10
end
end
end)
end)
end)