Oddly enough, it doesn’t print the result for some reason. I’ve changed the script to these changes, but nothing happens…
Serverscript
local function OreTransparency(player, Ore, localDebounce)
print("test")
local char = player.Character
local hum = char:FindFirstChildOfClass("Humanoid")
if not debounce then
if hum then
local pickaxe = char:FindFirstChild("Pickaxe")
if pickaxe then
for _, v in(Ore:GetChildren()) do
if v:IsA("BasePart") and v.Name ~= "Hitbox" then
v.Transparency += 0.25
if v.Transparency == 1 then
if Ore.Name == "Rock" then
print("rock!")
elseif Ore.Name == "IronOre" then
print("iron!")
end
end
end
end
debounce = true
task.wait(3)
debounce = false
end
end
end
if localDebounce == true then
localDebounce = false
return localDebounce
end
end
debounceFunction.OnServerInvoke = function(player, Ore, localDebounce)
OreTransparency(player, Ore, localDebounce)
end
Localscript
local AzureOre = script.Parent
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Hitbox = script.Parent:WaitForChild("Hitbox")
local replicatedStorage = game:GetService("ReplicatedStorage")
local debounceFunction = replicatedStorage.DebounceFunction
local Character = Player.Character or Player.CharacterAdded:Wait()
local Pickaxe = Character:WaitForChild("Pickaxe")
local Handle = Pickaxe:WaitForChild("Handle")
local Count = 0
local Active = false
local debounce = false
Hitbox.Touched:Connect(function(player)
local function Check()
if Handle:GetAttribute("IsActivated") == true and not debounce then
debounce = true
Count += 1
local Cast = workspace:Raycast(Handle.Position, Handle.CFrame.LookVector * 2)
if Cast then
if Cast.Instance.Name ~= AzureOre.Name then return end
else
return
end
end
end
repeat task.wait(1) Check() until Count == 5
local result = debounceFunction:InvokeServer(AzureOre, true)
print(result)
Count = 0
end)
I’m trying to find a way to communicate from the server to the client, to change the debounce value to false through the localdebounce variable on the server script
I’ve done this, but now the serverscript seems to be on an infinite loop upon the first click with the pickaxe tool. Now, the ore disappears regardless of if I click it once with the pickaxe. I’ve put a print statement below the OreTransparency function to show this off.
Here’s the server script, to see if the loop can be caught.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local debounceFunction = ReplicatedStorage.DebounceFunction
local OreTransparency = 0
local debounce = false
local debounce2 = false
local function OreTransparency(player, Ore, localDebounce)
print("test")
local char = player.Character
local hum = char:FindFirstChildOfClass("Humanoid")
if not debounce then
if hum then
local pickaxe = char:FindFirstChild("Pickaxe")
if pickaxe then
for _, v in(Ore:GetChildren()) do
if v:IsA("BasePart") and v.Name ~= "Hitbox" then
v.Transparency += 0.25
if v.Transparency == 1 then
if Ore.Name == "Rock" then
print("rock!")
elseif Ore.Name == "IronOre" then
print("iron!")
end
end
end
end
debounce = true
task.wait(3)
debounce = false
end
end
end
if localDebounce == true then
localDebounce = false
return localDebounce
end
end
debounceFunction.OnServerInvoke = function(player, Ore, localDebounce)
OreTransparency(player, Ore, localDebounce)
end
There is no need to reset count to 0, it is supposed to reach 5 which then should end the loop, but here it isn’t reaching 5 probably because of something wrong into the server script but i’m lazy to review the entire code so i let someone else trying to help him.
Nah, if the Hitbox is touched again then a new repeat loop will start using the current count value, and both loop will end when the count reach 5… you need to reset the count only when it reached 5, after the loop end.
Not sure, but i think that the repeat loop yield the code so touching the hitbox again could do nothing.
No, if you reset it once it reached 5 it shouldn’t go above it, but anyway yeah it still is an infinite loop as the process will run over and over again
There is no looping error, this is what the OP is attempting to do.
Inside the loop, the Check function is running and is setting the debounce value to true, then the RemoteFunction is fired, something is made in server side and it return false to the client so you can set the debounce value back to false to allow the Check function to run again… it is the current problem, i’m pretty sure that something in server side is wrong which cause it to never return false to the client and getting stuck at count 1 with the debounce value to true
What I’m trying to do is have a localscript which receives information from the server upon finishing up the transparency function, so that the debounce can be set to true when the function hasn’t started, and set to false whenever the transparency function concludes. As I wish to avoid the transparency function firing 15 times, and instead, only once.
I do set it back to 0 once the count has reached 5.
repeat task.wait(1)
Check()
local result = debounceFunction:InvokeServer(AzureOre, true)
if result then
debounce = result
end
until Count == 5
Count = 0
end)