#Shop tools dosent work

1 messages · Page 1 of 1 (latest)

woven plover
#

they dont give coins, and yes the coinsGiver intvalue is cloned too

vital fractal
#

idk

woven plover
#

Then why answear 😭

woven plover
#

maybe someones knows

elfin condor
#

@woven plover yo

#

imma try to help

#

js gonna inspect the code rq

woven plover
#

this is before adding prints

elfin condor
#

send pic after adding prints

#

so i know which parts run

woven plover
#

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

woven plover
elfin condor
woven plover
#

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?

elfin condor
#

add it everywhere

#

before functions

#

during functions

#

after functions

#

preperations

#

and etc

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)
    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

elfin condor
#

lemme add more print statements

#

then u can tell me what works

#

and what doesnt

woven plover
#

ok, I also added randomly printed statements

trim bladeBOT
#

studio** You are now Level 6! **studio

woven plover
#

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)

elfin condor
#

wait

#

lemme fix the prints

#

for a better understanding

woven plover
#

ok

elfin condor
#

@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

woven plover
#

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

elfin condor
#

okay

woven plover
#

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

elfin condor
#

looks like the client side is actually fucnitoning

#

and normal

#

send ss from server side

#

handling the remote

woven plover
#

want me to copy it

#

and paste it here

#

this is from datastore script

elfin condor
woven plover
#
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)```
elfin condor
#

anddd the toolscooldown is where?

woven plover
#

toolscooldown?

elfin condor
woven plover
#

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

elfin condor
#

ok send the full script

woven plover
#

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

woven plover
#

also this might help

worn gull
elfin condor
#

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

woven plover
worn gull
worn gull
elfin condor
worn gull
#

ye code looks fine, you're probably just not updating the gui or something

#

tho it is a leaderstat

woven plover
#

when I join, I buy the tool, I use it and use it again shortly

elfin condor
# woven plover

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

woven plover
#

I copy from buytoolremote ?

worn gull
woven plover
worn gull
worn gull
woven plover
elfin condor
#

press multiple times

#

so i can see the coins2 value

woven plover
worn gull
#

okay so both, well for the data part thats easy, you just missing game:bindtoclose

woven plover
woven plover
worn gull
worn gull
woven plover
woven plover
#

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

elfin condor
#

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

woven plover
#

CoinsGiving is not a valid member of Tool "Workspace.danielbani12.BasicCandy" - Client - LocalScript:18

trim bladeBOT
#

studio** You are now Level 7! **studio

woven plover
#

also I get this error but my tools give the right amount of coins

woven plover
elfin condor
#

so in serverside just check forr the value

#

and use that

woven plover
#

yeah, coinsGiving is a Intvalue of the tool

#

a hacker can acces the replicatedstorage?

worn gull
#

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