they dont give coins, and yes the coinsGiver intvalue is cloned too
#Shop tools dosent work
1 messages · Page 1 of 1 (latest)
idk
Then why answear 😭
maybe someones knows
this is before adding prints
the remote event dosent functions at all, this was hours ago, Iv deleted the script and worked on the tools shop remote event and added coins.Value += coinsGiving there, and moved coinsGiving from tools to buttons, it works but its not what I wanted
I can try putting the script back, but the remote event dosent work at all
js put em back and send pics after prints and the output
lemme see if I can recover or I have to write again
amazing Im meeting this dumb bug where my game is connecting to the server and stays stuck forever even tough my network isnt the problem
give me 5 more minutes
@elfin condor got the script back, where should I add print statements?
add it everywhere
before functions
during functions
after functions
preperations
and etc
local replicatedStorage = game:GetService("ReplicatedStorage")
local tools = replicatedStorage:FindFirstChild("Tools")
local toolsRemote = replicatedStorage:FindFirstChild("ToolsRemote")
local buyToolRemote = toolsRemote:FindFirstChild("BuyCandyRemote")
local player = game.Players.LocalPlayer
local backpack = player:WaitForChild("Backpack")
local debounce = {}
local function getTools(tool)
tool.Activated:Connect(function()
if debounce[tool] then return end
local player = game.Players.LocalPlayer
if player then
debounce[tool] = true
buyToolRemote:FireServer(tool.CoinsGiving.Value)
end
end)
end
for _, tool in pairs(backpack:GetChildren()) do
if tool:IsA("Tool") then
print("Tool")
getTools(tool)
end
end
backpack.ChildAdded:Connect(function(child)
if child:IsA("Tool") then
getTools(child)
end
end)
only "tool" is printed
thats because I have a tool in the starterpack
ok, I also added randomly printed statements
** You are now Level 6! **
so ive made some injections in the local script and got some results
local replicatedStorage = game:GetService("ReplicatedStorage")
local tools = replicatedStorage:FindFirstChild("Tools")
local toolsRemote = replicatedStorage:FindFirstChild("ToolsRemote")
local buyToolRemote = toolsRemote:FindFirstChild("BuyCandyRemote")
local player = game.Players.LocalPlayer
local backpack = player:WaitForChild("Backpack")
local debounce = {}
local function getTools(tool)
print("breakpoint1")
tool.Activated:Connect(function()
print("breakpoint2")
if debounce[tool] then print("breakpoint3") return end
local player = game.Players.LocalPlayer
if player then
print("breakpoint4")
debounce[tool] = true
buyToolRemote:FireServer(tool.CoinsGiving.Value)
end
end)
end
for _, tool in pairs(backpack:GetChildren()) do
print("breakpoint5")
if tool:IsA("Tool") then
print("Tool")
getTools(tool)
end
end
backpack.ChildAdded:Connect(function(child)
print("breakpoint5**")
if child:IsA("Tool") then
print("breakpoint5")
getTools(child)
print('breakpoint6')
end
end)
the script
when I join the game
when I buy the tool
when I use the tool(click)
ok
@woven plover
local replicatedStorage = game:GetService("ReplicatedStorage")
local tools = replicatedStorage:FindFirstChild("Tools")
local toolsRemote = replicatedStorage:FindFirstChild("ToolsRemote")
local buyToolRemote = toolsRemote:FindFirstChild("BuyCandyRemote")
local player = game.Players.LocalPlayer
local backpack = player:WaitForChild("Backpack")
local debounce = {}
local function getTools(tool)
print("Function getTools called.")
tool.Activated:Connect(function()
print("Tool activated, print statement from tool activation function")
if debounce[tool] then print("Tool found in debounce table, requesting return") return end
local player = game.Players.LocalPlayer
if player then
print("Player found")
debounce[tool] = true
buyToolRemote:FireServer(tool.CoinsGiving.Value)
print("Remote fired")
end
end)
end
for _, tool in pairs(backpack:GetChildren()) do
print("Child found in backpack")
if tool:IsA("Tool") then
print("Child turned out to be a tool.")
getTools(tool)
print("Called function getTools from finding tool")
end
end
backpack.ChildAdded:Connect(function(child)
print("Child added detected for backpack")
if child:IsA("Tool") then
print("Child was a tool added")
getTools(child)
print("getTools function called from backpact child added function")
end
end)
tell me the output frm that
so I replace the local script with this right?
Ill make 3 ss, one for joining, one for buying and one for activating the tool
okay
the fourth ss is when I use the tool Ive bough from the shop again
I also have a basic begginer tool in the starterpack
looks like the client side is actually fucnitoning
and normal
send ss from server side
handling the remote
yes
local replicatedStorage = game:GetService("ReplicatedStorage")
local toolsRemote = replicatedStorage:FindFirstChild("ToolsRemote")
local buyToolRemote = toolsRemote:FindFirstChild("BuyCandyRemote")
buyToolRemote.OnServerEvent:Connect(function(player, coinsGiver)
local now = tick()
local lastTimeUpdate = toolsCooldown[player.UserId] or 0
if now - lastTimeUpdate <= 0.5 then return end
toolsCooldown[player.UserId] = now
local coinsStats2 = player:FindFirstChild("leaderstats")
local coins2 = coinsStats2:FindFirstChild("Coins")
if coins2 then
coins2.Value += coinsGiver
coinsCache[player.UserId] = coins2.Value
end
end)```
anddd the toolscooldown is where?
toolscooldown?
oh is on the top of the script lemme send it
local dataStoreService = game:GetService("DataStoreService")
local playerInventory = dataStoreService:GetDataStore("PlayerInventory")
local playerCoins = dataStoreService:GetDataStore("PlayerInventory","PlayerCoins")
local coinsCache = {}
local toolCooldown = {}
local toolsCooldown = {}
this at the top
ok send the full script
I think is too big to send in a full message lemme split it
local dataStoreService = game:GetService("DataStoreService")
local playerInventory = dataStoreService:GetDataStore("PlayerInventory")
local playerCoins = dataStoreService:GetDataStore("PlayerInventory","PlayerCoins")
local coinsCache = {}
local toolCooldown = {}
local toolsCooldown = {}
task.spawn(function()
while true do
task.wait(60)
for userId, value in pairs(coinsCache) do
pcall(function()
playerCoins:SetAsync(userId,value)
end)
end
end
end)
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local coins = Instance.new("IntValue",leaderstats)
coins.Name = "Coins"
local alreadyPurchased = Instance.new("Folder", player)
alreadyPurchased.Name = "AlreadyPurchased"
local succesCoins, currentCoins = pcall(function()
return playerCoins:GetAsync(player.UserId)
end)
if succesCoins then
if currentCoins == nil then
currentCoins = 0
pcall(function()
playerCoins:SetAsync(player.UserId,currentCoins)
end)
end
end
coinsCache[player.UserId] = currentCoins
coins.Value = currentCoins
end)
local basicCandyRemote = game.ReplicatedStorage:WaitForChild("ToolsRemote"):WaitForChild("BasicCandyRemote")
basicCandyRemote.OnServerEvent:Connect(function(player)
local now = tick()
local lastTimeUpdate = toolCooldown[player.UserId] or 0
if now - lastTimeUpdate <= 0.5 then return end
toolCooldown[player.UserId] = now
local coinStats = player:FindFirstChild("leaderstats")
local coins = coinStats:FindFirstChild("Coins")
if coins then
coins.Value += 1
coinsCache[player.UserId] = coins.Value
end
end)
local toolsRemote = game.ReplicatedStorage:WaitForChild("ToolsRemote")
local toolsRemoteFunction = toolsRemote:WaitForChild("ToolsRemoteFunction")
toolsRemoteFunction.OnServerInvoke = function(player, toolName, toolPrice)
local alreadyPurchased = player:FindFirstChild("alreadyPurchased")
if alreadyPurchased and alreadyPurchased:FindFirstChild(toolName) then return "owned" end
local invstats = player:FindFirstChild("leaderstats")
local coins =invstats:FindFirstChild("Coins")
if coins.Value >= toolPrice then
coins.Value -= toolPrice
local tool = game.ReplicatedStorage:WaitForChild("Tools"):FindFirstChild(toolName)
if tool then
local toolClone = tool:Clone()
toolClone.Parent = player.Backpack
toolClone.Name = toolName
local toolPurchased = Instance.new("BoolValue",alreadyPurchased)
toolPurchased.Name = toolName
end
return "Purchased succesfull"
else return "NotEnough"
end
end
local replicatedStorage = game:GetService("ReplicatedStorage")
local toolsRemote = replicatedStorage:FindFirstChild("ToolsRemote")
local buyToolRemote = toolsRemote:FindFirstChild("BuyCandyRemote")
buyToolRemote.OnServerEvent:Connect(function(player, coinsGiver)
local now = tick()
local lastTimeUpdate = toolsCooldown[player.UserId] or 0
if now - lastTimeUpdate <= 0.5 then return end
toolsCooldown[player.UserId] = now
local coinsStats2 = player:FindFirstChild("leaderstats")
local coins2 = coinsStats2:FindFirstChild("Coins")
if coins2 then
coins2.Value += coinsGiver
coinsCache[player.UserId] = coins2.Value
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerId = player.UserId
local coinstats = player:FindFirstChild("leaderstats")
local coins = coinstats:FindFirstChild("Coins")
if coins then
coinsCache[playerId] = coins.Value
pcall(function()
playerCoins:SetAsync(playerId,coins.Value)
end)
end
end)
```
the datastore script
add a print to this
also this might help
breakpoint4 is immediately before the fireserver, so the issue is on receiving side
yeah
client side seems fine
local dataStoreService = game:GetService("DataStoreService")
local playerInventory = dataStoreService:GetDataStore("PlayerInventory")
local playerCoins = dataStoreService:GetDataStore("PlayerInventory","PlayerCoins")
local coinsCache = {}
local toolCooldown = {}
local toolsCooldown = {}
local replicatedStorage = game:GetService("ReplicatedStorage")
local toolsRemote = replicatedStorage:FindFirstChild("ToolsRemote")
local buyToolRemote = toolsRemote:FindFirstChild("BuyCandyRemote")
buyToolRemote.OnServerEvent:Connect(function(player, coinsGiver)
local now = tick()
local lastTimeUpdate = toolsCooldown[player.UserId] or 0
if now - lastTimeUpdate <= 0.5 then return end
toolsCooldown[player.UserId] = now
local coinsStats2 = player:FindFirstChild("leaderstats")
local coins2 = coinsStats2:FindFirstChild("Coins")
if coins2 then
print("coins 2 found")
coins2.Value += coinsGiver
coinsCache[player.UserId] = coins2.Value
print("After coins cache")
end
end)
send output of that
a print to replicated storage?
hold in mind that the remote is buyToolRemote which is repstorage.ToolsRemote.BuyCandyRemote
which appears to match this
@woven plover can u send output of this?
ye code looks fine, you're probably just not updating the gui or something
tho it is a leaderstat
when I join, I buy the tool, I use it and use it again shortly
local dataStoreService = game:GetService("DataStoreService")
local playerInventory = dataStoreService:GetDataStore("PlayerInventory")
local playerCoins = dataStoreService:GetDataStore("PlayerInventory","PlayerCoins")
local coinsCache = {}
local toolCooldown = {}
local toolsCooldown = {}
local replicatedStorage = game:GetService("ReplicatedStorage")
local toolsRemote = replicatedStorage:FindFirstChild("ToolsRemote")
local buyToolRemote = toolsRemote:FindFirstChild("BuyCandyRemote")
buyToolRemote.OnServerEvent:Connect(function(player, coinsGiver)
local now = tick()
local lastTimeUpdate = toolsCooldown[player.UserId] or 0
if now - lastTimeUpdate <= 0.5 then return end
toolsCooldown[player.UserId] = now
local coinsStats2 = player:FindFirstChild("leaderstats")
local coins2 = coinsStats2:FindFirstChild("Coins")
if coins2 then
print("coins 2 found")
coins2.Value += coinsGiver
print(coins2.Value)
coinsCache[player.UserId] = coins2.Value
print("After coins cache")
end
end)
try this
to see the value of the coins2
I copy from buytoolremote ?
so the remote is fine, what is the problem?
gui isnt the problem
coins isnt updating, neither the data
no see that's an http://xyproblem.info
so coins are in fact being given, the problem is it's not saving?
the coins arent given(no update in the leaderstats) and data isnt savin so when I rejoined isnt like its updated
add me: Mertkk1235
okay so both, well for the data part thats easy, you just missing game:bindtoclose
ive press, you can see from aftrcoin cache to below
Im still a half-begginer, still dont know what bindtoclose is 😭
its not saving in studio since it is server shutdown, playerremoving doesn't get called properly
oh i see, pff you never set debounce[tool] to false on the client
reasonable, but that seems anotherproblem from this cuz my basictool works properly
yeah lemme fix it real quick, forgot about it
Ok so, WHAT THE HECK, WHY IS IT WORKING NOW
but even before that debounce system it was not working, what has chaged?
also guys I have a last question, is It ok to use coinGiver? seems easy to hack and modify it
u should handle that from server side
u could pass over the tool instance as an argument
and make the serverside handle the tool.coinsgiver value
CoinsGiving is not a valid member of Tool "Workspace.danielbani12.BasicCandy" - Client - LocalScript:18
** You are now Level 7! **
also I get this error but my tools give the right amount of coins
hmm thats right, but how do I make it different for each tool?
according to the hierarchy u have a value under the tol
so in serverside just check forr the value
and use that
yeah, coinsGiving is a Intvalue of the tool
a hacker can acces the replicatedstorage?
idk why you dont just give the tool a server script and do it that way, there's not really a point to having it a localscript