Script only recognizes one gun even tho the script prints correct gun name

Hello,i have been having issues with a server script not registering attribute even tho it prints it as false when using the print function.i will send both server and local code.

Server script:

local basebutton = game.ReplicatedStorage.TxtFolder.BuyButton
local scrollframe = script.Parent.ScrollingFrame:GetChildren()
local purchasableitems = game.ReplicatedStorage.PurchasableItems

local event = game.ReplicatedStorage.Remotes.Buying
local money = game.Workspace.GameProcess.SharedPlayerStats.Money

for i,holder in scrollframe do
if holder:IsA('Frame') then 
	local c = holder:GetAttribute("Category")
	local f = holder:GetAttribute("Folder")

	print(c)
	print(f)

	local folder = purchasableitems:FindFirstChild(c):FindFirstChild(f)

	for i,gun in folder:GetChildren() do
		local buy = basebutton:clone()
		buy.Parent = holder.TileSet
		buy.Text = gun.Name.." - <font color='rgb(113, 255, 105)'>"..gun:GetAttribute("Price").."$</font>"
		buy.DGun.Value = gun
		print(gun.Name)
	end
end
end

event.OnServerEvent:Connect(function(player,gun2buy)
print(gun2buy)
if gun2buy:GetAttribute("Bought") == false then
	local ifcanafford = gun2buy:GetAttribute("Price")
	if money.Value >= ifcanafford then
		money.Value -= ifcanafford
		gun2buy:SetAttribute("Bought",true)
		if player.Backpack:FindFirstChild(gun2buy.Name) == nil and player.Character:FindFirstChild(gun2buy.Name) == nil then
			gun2buy:Clone().Parent = player.Backpack
		end
	end
else
	if player.Backpack:FindFirstChild(gun2buy.Name) == nil and player.Character:FindFirstChild(gun2buy.Name) == nil then
		gun2buy:Clone().Parent = player.Backpack
	end
end
end)

Local script:

local player = game.Players.LocalPlayer
local guiweneed = player.PlayerGui.ShopGui.MainBit.ActualThing.SelectedObject
local othergui = player.PlayerGui.ShopGui.MainBit.ActualThing.MainBit
local desiredgun = script.Parent.DGun

local event = game.ReplicatedStorage.Remotes.Buying

script.Parent.MouseButton1Click:Connect(function()
if guiweneed.Visible == false or guiweneed.GunName.Text ~= desiredgun.Value.Name then
	guiweneed.Visible = true
	guiweneed.GunName.Text = desiredgun.Value.Name
	guiweneed.Price.Text = desiredgun.Value:GetAttribute("Price").."$"
	guiweneed.Description.Text = desiredgun.Value:GetAttribute("Description")
	
	local displayframe = guiweneed.DisplayFrame
	
	if desiredgun.Value:GetAttribute("Bought") == true then
		guiweneed.BuyButton.Text = "Equip"
	else
		guiweneed.BuyButton.Text = "Purchase"
	end
	for _,instance in displayframe:GetChildren() do
		if instance:IsA('Model') then
			instance:Destroy()
		end
	end
	
	local gunclone = desiredgun.Value.Parts.GunDisplay:Clone()
	gunclone:MoveTo(Vector3.new(0,0,0));
	gunclone.Parent = displayframe
	othergui.Size = UDim2.new(0,520,1,0)
else
	othergui.Size = UDim2.new(0,720,1,0)
	guiweneed.Visible = false
end
 end)

guiweneed.BuyButton.MouseButton1Click:Connect(function(purchase)
local gun2buy = desiredgun.Value
if guiweneed.GunName.Text == desiredgun.Value.Name then
	event:FireServer(gun2buy)
	task.wait(0.1)
	if desiredgun.Value:GetAttribute("Bought") == true then
		print("suces")
	else
		print("fail")
	end
end
end)

desiredgun.Value:GetAttributeChangedSignal("Bought"):Connect(function()
print("test")
if desiredgun.Value:GetAttribute("Bought") == true then
	guiweneed.BuyButton.Text = "Equip"
	script.Parent.Text = desiredgun.Value.Name.." - <font color='rgb(113, 255, 105)'>BOUGHT</font>"
end
end)

This is how the attributes look:
a6c540f4859aa6094fec41cf1a43c522

Any help would be appreciated.

1 Like

Just wondering, how are you determining whether the event worked or not? I see you used a task.wait(0.1) thats not such a good idea, because a remote event could take longer.

1 Like

doesnt work,the problem is not that the remote event doesnt fire,it also does recognize the attributes so i have no clue what could cause it.

It fixed itself,i have no clue how but im not complaining.

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