Concatenation problem

So I followed a solution recently and came into a problem(as I usually do)

So basically for some reason concatenation is not working and instead it calls the value “ammo” instead of the full name
Any reason why this is happening?

local damage = {}
local config
function damage.IdentifyGun(gunname, target, muzzleeffect, plr, gunshot, player)
	local debounce = false
	local character = player.Character or player.CharacterAdded:Wait()
config = script.Configuration
local folder = config:FindFirstChild(gunname)
local damagevar = folder.Damage
local ammovar = folder.Ammo
local clone
local ammovalue = Instance.new("IntValue")
ammovalue.Parent = character
print("fgv")
 clone = ammovalue:Clone()
clone.Name = "ammo " .. folder.Name
local counter = 0
for i,v in pairs(character:GetChildren()) do
	print("dffg")
		if v.Name == clone.Name then
			print("gfdgv")
		counter +=1
	end
	if counter >=2 then
		print("bruhh")
			clone:Destroy()
	end
end
local ammo = character:FindFirstChild("ammo " .. gunname)
if ammo == nil then return end

local fireratevar = folder.FireRate
local reloadtimevar = folder.ReloadTime
local maxammovar = folder.MaxAmmo
if target == nil then
	return
end
		if ammo.Value > 0 and debounce == false then
		warn(ammo.Value .. " IS THE AMMO VALUE")
warn(fireratevar.Value .. " IS THE FIRERARE VALUE!")
			ammo.Value -=1
		muzzleeffect.Enabled = true
		gunshot:Play()
		debounce = true
		if target.Parent:FindFirstChild("Humanoid") then
			target.Parent.Humanoid:TakeDamage(damagevar.Value)
		end
		task.wait(fireratevar.Value)
		debounce = false
		muzzleeffect.Enabled = false
			if ammo.Value == 0 then
				debounce = true
				task.wait(reloadtimevar.Value)
				ammo.Value = maxammovar
				debounce = false
				return
			end
end
end
return damage
local replicatedstorage = game:GetService("ReplicatedStorage")
local rt = replicatedstorage:WaitForChild("Shoot")
local serverscriptserver = game:GetService("ServerScriptService")
local module = require(serverscriptserver.DamageModule)
local soundservice = game:GetService("SoundService")
local sound = soundservice["Gun Shot"]
rt.OnServerEvent:Connect(function(plr, mouse, tool,pos, targetfilter)
	local muzzle = tool.Effect.MuzzleEffect
	--- print(targetfilter)
	targetfilter = tool.Handle
module.IdentifyGun(tool.Name, mouse, muzzle, plr.Name, sound, plr)
end)

Repost because the other one stopped getting replies

Try removing the space after …

No, unfortunately this did not work.

Can somebody PLEASE help me with this

You have to give ammo a parent or it’ll instantly become nil

1 Like

Please indent the code (for us), unless you want to have your intelligence insulted.

I noticed that in this code, there’s quite a lot of boilerplate / unnecessary complexity, so I’ll go over most, if not of all of them, and fix them along the way (this calls for a complete rewrite).

Also, check out the Roblox Lua Style guide. It’s source of my main points.

  • Keep the number of arguments to a given function small, preferably 1 or 2.
  • All services should be referenced using game:GetService at the top of the file.
  • Use PascalCase names for class and enum-like objects.
  • “Debounces” are declared OUTSIDE their respective function, not inside.
  • File structure:
  • Declare module-level variables (variables that last for the entirety of the script) at the top, beneath module imports, below the services used.

A little something like this:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local SoundService = game:GetService("SoundService")

local DamageModule = require(ServerScriptService.DamageModule)

local shotEvent = ReplicatedStorage:WaitForChild("Shoot")
local gunShotSound = SoundService["Gun Shot"]

...

For the actual debugging, I found it a bit hard to do, because I have no idea what error message appeared (if there even was one). My first assumption though, is that because you’re sending a Mouse object from the client → server (see why this doesn’t work), the order of the parameters get shifted.

In other words, when you do

-- client

ShotEvent:FireServer(function(mouse, tool, pos, targetFilter)

-- you're actually doing

ShotEvent:FireServer(function(tool, pos, targetFilter)

Though I’m not sure, and this statement is likely to incorrect. After all, if this was the case, you’d be calling IdentifyGun with pos.Name in place of tool.Name, which should give an error (assuming pos is a Vector3)

1 Like