Hello everyone,
I am scripting a new passion project of mine recently and I ran into a bit of an issue.
As pictured below in the code from the LocalScript, I am trying to fire a remote event while passing the name of the tool that the event was fired from. In this case the tools name is “Basic Martial Arts Manual”.
--[[Tool]]
local Manual = script.Parent
local manualName = Manual.Name
--[[Events]]
local manualEvent = game:GetService("ReplicatedStorage").Events.General.ManualEvent
--[[Player]]
local plr = game:GetService("Players").LocalPlayer
--[[Stuff]]
local db = false
local cd = 5
local function eventer()
if db == false then
db = true
manualEvent:FireServer(Manual.Name)
wait(cd)
db = false
end
end
Manual.Activated:Connect(eventer)
And below is the ManualManager Script that is connecting this event to a function:
--[[Services]]
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local SS = game:GetService("ServerStorage")
local RunService = game:GetService("RunService")
--[[Folders]]--
local chars = workspace.Characters
--[[Modules]]--
local manualModule = require(SS.Modules.ManualModule)
local skillsModule = require(SS.Modules.LearningModule)
--[[Events]]--
local manualEvent = RS.Events.General.ManualEvent
--
local function manualDeleter(plr, manualName)
-- removing manual after use
if plr.Character:FindFirstChild(manualName) then
plr.Character:FindFirstChild(manualName):Destroy()
elseif plr.Backpack:FindFirstChild(manualName) then
plr.Backpack:FindFirstChild(manualName):Destroy()
else -- if the event was fired with no manual in inventory then they get no skills
return false
end
return true
end
local function manualManager(player, manualName)
print(manualName)
if not workspace.Characters:FindFirstChild(player.Name) then return end
print(player.Name.." used: "..manualName)
--chance that general basic manuals are too vague to teach you anything
if manualName == "Basic Martial Arts Manual" then
local result = math.random(1,3)
if result == 1 then
print("Manual was in too bad of a condition to learn anything useful...")
manualDeleter(player, manualName)
return
end
end
local manualFound = manualDeleter(player, manualName)
if manualFound == true then
local taughtSkill = manualModule.findSkill(player, manualName)
skillsModule.teachSkill(player, taughtSkill)
end
end
manualEvent.OnServerEvent:Connect(manualManager)
There’s no need for me to include the module scripts as the error is generating on line #40 when I try to print the the player.Name and the manualName. It seems like the event and script function as intended the very first time they are activated, but on following firings of the event, the args passed through are incorrect.
15:19:27.277 Basic Martial Arts Manual - Server - ManualManager:36
15:19:27.278 g_rimblo used: Basic Martial Arts Manual - Server - ManualManager:40
15:19:27.278 Manual was in too bad of a condition to learn anything useful… - Server - ManualManager:47
15:19:35.210 g_rimblo - Server - ManualManager:36
15:19:35.211 ServerScriptService.ManualManager:40: attempt to concatenate string with Instance - Server - ManualManager:40
15:19:35.212 Stack Begin - Studio
15:19:35.212 Script ‘ServerScriptService.ManualManager’, Line 40 - function manualManager - Studio - ManualManager:40
15:19:35.212 Stack End - Studio
As seen in the above error output, the issue is that the player is somehow being passed through the RemoteEvent in the argument position that should be occupied by the Manual.Name on the subsequent uses of the tool.
I have tried a few things, but have not found success in fixing this. One method was hardcoding the value that is passed through, but that didn’t work on subsequent activations as well:
manualEvent:FireServer("Basic Martial Arts Manual")
Please let me know if anyone has insight into this topic!
Thank you,
g_rimblo