Setting up attributes on the server, but only shows up on the client

so I did a client-server communication where the server will be setting up the attributes for the ammo and magazine. the code below is the serverscript that setup attributes

signal:OnEvent("InitGun", function(plr, tool)
	local weapon = framework.new(tool, plr.Character)
	
	if not tool:GetAttribute("Ammo") and not tool:GetAttribute("Magazine") then
		print("Setting up attributes")
		tool:SetAttribute("Ammo", weapon.Configuration.Ammo)
		tool:SetAttribute("Magazine", weapon.Configuration.Magazine)
	end
	
	print(tool:GetAttribute("Ammo"))
	
	print("Server initialized")
end)

for some reason, it is printing nil on the server
image

but still shows up on the client. I need assistance with this. it might be a stupid error I made, but I’m still unaware of the problem. thanks!
image

3 Likes

Did you fire the event? That could be the reason

1 Like

yes I did fire the event. not sure why’s that the reason, because the last time I did this it was working fine.

char.ChildAdded:Connect(function(child)
	if child:IsA("Tool") then
		signal:FireServer("InitGun", child)
		
		weapon = framework.new(child)
		status = weapon.Status
	end
end)

Speaking from my own experience, sending more than one argument can get disorienting for the code. To check if your arguments are being sent correctly, can you run the following?

Sending the arguments

char.ChildAdded:Connect(function(child)
	if child:IsA("Tool") then
	print(child)
		signal:FireServer("InitGun", child)
...

Receiving the arguments

signal:OnEvent("InitGun", function(plr, tool)
	print(plr, tool)
	local weapon = framework.new(tool, plr.Character)
...

Then please share the print outputs.

2 Likes

image
the arguments are correct

1 Like

So I have never worked with attributes so don’t judge me on this…

tool:SetAttribute("Ammo", weapon.Configuration.Ammo)
tool:SetAttribute("Magazine", weapon.Configuration.Magazine)

So in these lines shouldn’t there be weapon.Configuration.Ammo.Value by any chance?

1 Like

alright so I decided to create a BoolValue when the server attempts to set the attributes.
image

the BoolValue was shows on both the client and server. which is pretty strange that attributes doesn’t behave the same.

image
(this is a server view)

1 Like

no, the configurations are a table

2 Likes

I mean if you want to you can check this tutorial it uses attributes. I know its probably not the right thing but it may help.

1 Like

check if weapon.Configuration.Ammo is nil dummy XP

1 Like

I am afraid I can not help any further. I suggest forking through the following;

  • Variables
    Maybe you have a wrong path listed to a variable?
  • Module
    As you said, it’s a table. Make sure values are correct, the right path is being followed in the line weapon.Configuration.Ammo & -.Magazine.
  • Add more print statements.
    Any that lead closer to the issue. Example; print(weapon, weapon.Configuration, weapon.Configuration.Ammo)

Other than that, I do not know what the issue is. Do update this topic whenever you find something of a clue of what the problem is.

1 Like

What does the Configuration module look like? The only way for “Ammo” to be nil after setting it is that Configuration.Ammo is nil.

1 Like

…yeah I completely have the wrong path for the Ammo and Magazine just like what @Demo_Liti0n and @Judgy_Oreo said. should’ve done more debugging next time. thanks for your answers everyone!

1 Like

You replied to the wrong person but ok :grin:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.