Carrying on from the help topic I just resolved regarding my weapon system, I’m now working on a system for one-time use tools. I’m going to stay light on the details (unless necessary otherwise) this time around because the problem is that, about 50% of the time during runtime, a specific remote function will straight up not :InvokeServer()
when I tell it to. The function in question is called QueryInfo and is meant to gather information from server storage and return it to the client for proper tool and weapon handling. When I try to get that information, however, it will not communicate with the server; I know this because I’ve put print()
statements in the .OnServerInvoke()
function and they didn’t print anything in the output. This random nonfunctioning of QueryInfo has ground work on this system to a halt because I can’t test any of the tools unless I can get information from server storage. I’ve pasted the entire weapon system (from a game file where QueryInfo worked 100% of the time) into the game file with the one-time tool system and now even the scripts that utilize QueryInfo from the weapon system no longer work half the time.
Here are the implementations:
-- tool system local
character.ChildAdded:Connect(function(tool)
if tool.ClassName ~= "Tool" then return end -- return if it's not a tool that's being added
--zeroing out connections
if equipConnection then equipConnection:Disconnect() equipConnection = nil end
if unequipConnection then unequipConnection:Disconnect() unequipConnection = nil end
-- grabbing the tool handle and attributes
local handle = tool:WaitForChild("Handle")
local throwable = tool:GetAttribute("Throwable") or nil
local consumable = tool:GetAttribute("Consumable") or nil
if not throwable and not consumable then return end
-- function that runs when the tool is equipped
equipConnection = tool.Equipped:Connect(function()
--zeroing out connections
if inputBegin then
inputBegin:Disconnect()
inputBegin = nil
end
RANGE, TIMER, DURATION, HEALTH = queryInfo:InvokeServer(tool)
print(RANGE, TIMER, DURATION, HEALTH)
-- tool system server
function queryInfo.OnServerInvoke(player, tool)
local itemConfig = getConfig(tool)
print(itemConfig)
if not itemConfig then return end
local range, timer, duration, health
if itemConfig:FindFirstChild("Range") then range = itemConfig.Range.Value end
if itemConfig:FindFirstChild("Timer") then timer = itemConfig.Timer.Value end
if itemConfig:FindFirstChild("Duration") then duration = itemConfig.Duration.Value end
if itemConfig:FindFirstChild("Health") then health = itemConfig.Health.Value end
return range, timer, duration, health
end
-- weapon system local
character.ChildAdded:Connect(function(tool)
if tool.ClassName ~= "Tool" then return end -- return if it's not a tool that's being added
--zeroing out connections
if equipConnection then equipConnection:Disconnect() equipConnection = nil end
if unequipConnection then unequipConnection:Disconnect() unequipConnection = nil end
-- grabbing the tool handle and attributes
local handle = tool:WaitForChild("Handle")
local slashAnim = handle:FindFirstChild("Slash")
local automatic = tool:GetAttribute("Automatic") or nil
local melee = tool:GetAttribute("Melee") or nil
if tool:GetAttribute("Throwable") or tool:GetAttribute("Consumable") then return end
-- function that runs when the tool is equipped
equipConnection = tool.Equipped:Connect(function()
--zeroing out connections
if inputBegin then inputBegin:Disconnect() inputBegin = nil end
if inputEnd then inputEnd:Disconnect() inputEnd = nil end
if firing then firing = nil end
-- retrieve info, handle animations and GUI elements
print("here")
FIRE_RATE, FIRE_SPEED, FIRE_RANGE, FIRE_SPREAD, FIRE_BURST, FIRE_SHOT, mag, ammo = queryInfo:InvokeServer(tool)
print(FIRE_RATE, FIRE_SPEED, FIRE_RANGE, FIRE_SPREAD, FIRE_BURST, FIRE_SHOT, mag, ammo)
-- weapon system server
function queryInfo.OnServerInvoke(player, tool)
local weaponConfig = getConfig(tool)
if not weaponConfig then return end
local fireRate, fireSpeed, range, spread, burst, shot, mag, ammo
if weaponConfig:FindFirstChild("FireRate") then fireRate = weaponConfig.FireRate.Value end
if weaponConfig:FindFirstChild("FireSpeed") then fireSpeed = weaponConfig.FireSpeed.Value end
if weaponConfig:FindFirstChild("Range") then range = weaponConfig.Range.Value end
if weaponConfig:FindFirstChild("Spread") then spread = weaponConfig.Spread.Value end
if weaponConfig:FindFirstChild("Burst") then burst = weaponConfig.Burst.Value end
if weaponConfig:FindFirstChild("Shot") then shot = weaponConfig.Shot.Value end
local stock = getAmmo(player, tool)
if not stock and weaponConfig:FindFirstChild("MaxAmmo") and weaponConfig:FindFirstChild("MagSize") then stock = ammoSetup(player, tool) end
if stock then mag, ammo = stock:GetAttribute("Ammo").X, stock:GetAttribute("Ammo").Y end
print(fireRate, fireSpeed, range, spread, burst, shot, mag, ammo)
return fireRate, fireSpeed, range, spread, burst, shot, mag, ammo
end
Let me know if I need to provide any more info.