Hello ! I have a little problem. I use a public mining system i found at the internet, everything work correctly. The system i use work with the scoreboard, and me, i use a different system ( database & ui ). So, when the tree have 0 HP, he spawn 3 logs, and in this logs, there are click detector, and when i click on it, it destroy the log, and give me money. But it doesnt work !
local wood = game.ReplicatedStorage.Logs:Clone()
wood.Parent = workspace
wood:MoveTo(script.Parent.Position)
ongoing = false
health = 100 -- [ Put the original health here ] --
wait(respawn)
for i, x in pairs(script.Parent.Parent:GetChildren()) do
x.Transparency = 0
x.CanCollide = true
end
This code is for spawning log ( i just show a little part, not the entire script ). This is the log i want to be spawn:
After that, in the server script storage, i do the money system :
local logs = game.ReplicatedStorage.Logs.Part1.ClickDetector
logs.MouseClick:Connect(function(hit23)
local player = players:GetPlayerFromCharacter(hit23.Character)
if player then
local name = player.Name --got name
print(name)
local currencyStore = DataStore("currency", players[name])
wait(0.2)
currencyStore:Increment(5000)
end
end)
Do you have an idea of why isnt working ? ( sorry for my bad english, im french )
I see where your mistake is. You made a line like this:
local player = players:GetPlayerFromCharacter()(hit.Humanoid)
it should be:
local player = players:GetPlayerFromCharacter(hit.Humanoid)
Edit: I also recommend using Mouse or UserInputService in order to check if the player did something with their keyboard/mouse or not.
The issue has to lie within your datastore code, not here, the code looks okay. Also, why are you getting the name of the player and using that for the datastore when you can just give it the player instance that MouseClick gives
local logs = game.ReplicatedStorage.Logs.Part1.ClickDetector
logs.MouseClick:Connect(function(player)
local currencyStore = DataStore("currency", player)
wait(0.2)
currencyStore:Increment(5000)
end)
yes sure :
local players = game:GetService(“Players”)
local replicatedStorage = game:GetService(“ReplicatedStorage”)
local DataStore = require(1936396537)
local defautCurrencyAmount = 50
players.PlayerAdded:Connect(function(player)
local currecyStore = DataStore("currency", player)
local function updateClientCurrency(amount)
replicatedStorage.RemoteEvents.UpdateClientCurrency:FireClient(player, amount)
end
updateClientCurrency(currecyStore:Get(defautCurrencyAmount))
currecyStore:OnUpdate(updateClientCurrency)
end)
Firstly, get the Datastore2 module from Github than using the module on Roblox to ensure it’s the latest version, also you forgot a crucial step to combine the data, basically, after local defautCurrencyAmount = 50, add this line
DataStore.Combine("DATA","currency")
You need to do this for the DataStore to work properly for DataStore2
No … I didnt work. I think the error is not the database, but when i spawn my log. Like, when i click on the log, it didnt disappear.
local health = 100
local bool = true
local ongoing = true
local respawn = math.random(8,20)
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('IsAAxe') and ongoing == true then
local status = hit.Parent:FindFirstChild('Type')
if health > 0 then
if status.Value == 'Common' then
health = health - 5
elseif status.Value == 'Uncommon' then
health = health - 10
elseif status.Value == 'Rare' then
health = health - 15
elseif status.Value == 'Epic' then
health = health - 20
end
elseif health <= 0 and bool == true then
bool = false
for i, x in pairs(script.Parent.Parent:GetChildren()) do
x.Transparency = 1
x.CanCollide = false
end
local wood = game.ReplicatedStorage.Logs:Clone()
wood.Parent = workspace
wood:MoveTo(script.Parent.Position)
ongoing = false
health = 100 -- [ Put the original health here ] --
wait(respawn)
for i, x in pairs(script.Parent.Parent:GetChildren()) do
x.Transparency = 0
x.CanCollide = true
end
bool = true
ongoing = true
end
end
end)
You don’t have code in your MouseClick event that destroys the log, your issue is also that it’s getting the logs from the one in ReplicatedStorage. Try this out
local logs = script.Parent
logs.ClickDetector.MouseClick:Connect(function(player)
local currencyStore = DataStore("currency", player)
wait(0.2)
currencyStore:Increment(5000)
logs.Parent:Destroy()
end)
It’ll use logs as the parent of the script and then does the code accordingly, click on the part, get money, and destroy the model, you could repalce
logs.Parent:Destroy()
with
logs:Destroy()
To destroy a single log if that’s what you wanted
Wait what do you mean by this? For it not destroying, something else for some reason is preventing the script from working. Try adding a print in the event to see if it’s actually really not working. If so, I think something else is going on
it doesnt work, but when i put the script in here :
It work. ( in the remover script )
Ok so first → it spawn the right log because it destroy when i click on it ( using the remover script ), so now im sure it spawn the right one. BUT, i dont get the money when i click on it.
If you want i gave all my code in the service script service :
local players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local DataStore = require(1936396537)
local defautCurrencyAmount = 50
DataStore.Combine("DATA","currency")
players.PlayerAdded:Connect(function(player)
local currecyStore = DataStore("currency", player)
local function updateClientCurrency(amount)
replicatedStorage.RemoteEvents.UpdateClientCurrency:FireClient(player, amount)
end
updateClientCurrency(currecyStore:Get(defautCurrencyAmount))
currecyStore:OnUpdate(updateClientCurrency)
end)
replicatedStorage.RemoteEvents.ItemPurchase.OnServerEvent:Connect(function(player, itemName)
if replicatedStorage.Items:FindFirstChild(itemName) then
local price = replicatedStorage.Items[itemName].Price.Value
local currencyStore = DataStore("currency", player)
if currencyStore:Get(defautCurrencyAmount) >= price then
currencyStore:Increment(-price)
local item = replicatedStorage.Items[itemName]:Clone()
item.Parent = player.Backpack
end
end
end)
local buttonStation1 = workspace.Button2.Button.ClickDetector
local buttonStation1Entree = workspace.POS2
local logs = game.ReplicatedStorage.Logs.Part1.ClickDetector
logs.MouseClick:Connect(function(player)
print("test2")
local currencyStore = DataStore("currency", player)
wait(0.2)
currencyStore:Increment(5000)
logs:Destroy()
end)
buttonStation1.MouseClick:Connect(function(hit2)
local player = players:GetPlayerFromCharacter(hit2.Character)
if player then
local name = player.Name --got name
print(name)
local currencyStore = DataStore("currency", players[name])
wait(0.2)
currencyStore:Increment(-50)
end
end)
local cheat = workspace.cheat
cheat.Touched:Connect(function(hit)
local player = players:GetPlayerFromCharacter(hit.Parent)
if player then
local name = player.Name --got name
print(name)
local currencyStore = DataStore("currency", players[name])
wait(0.2)
currencyStore:Increment(5000000)
end
end)
--while wait(1) do
-- for k, v in pairs(players:GetChildren()) do
-- local currencyStore = DataStore("currency", v)
-- currencyStore:Increment(1)
-- end
--end
local recentObbyPlayers = {}
local obbyAward = -75
The reason it works when it’s there is because of how the variables are set, you’d have to make the Remover script be in one of the logs itself, you can’t do it how you’re doing it unfortunately for the logs, has to be from a script inside of it. Also for the money, could you add a print inside updateClientCurrency to see if it’s actually running that when you update the datastore? It could be something wrong with the ClientEvent