Attempt to compare Instance <= Instance

In this script, I’m trying to add a reload part. I’m trying to make it so when you reload, it takes away the amount of ammo you took from the max ammo. Hard to explain. However, I got an error on the activated part which tells it to shoot.

script.Parent.Activated:Connect(function()
		if canshoot and not reloading then
			if script.Parent.Ammo <= script.Parent.MaxAmmo and script.Parent.Ammo > 0 then
				canshoot = false
				Shoot()
				for i,v in pairs (shootpart:GetChildren()) do
					if v:IsA("SpotLight") or v:IsA("ParticleEmitter") then
						v.Enabled = true
						print("Shot")
						wait(0.05)
						v.Enabled = false 
					end
				end
				wait(0.3)
				canshoot = true
			elseif ammo == 0 then
				reload()
				reloading = true
				canshoot = false
				wait(reloadTime)
				reloading = false
				canshoot = true
			end
		end
	end)

Please let me know if you have suggestions.

1 Like

Are they IntValues? If so, add .Value to the end of it.

2 Likes

can you show me what ammo/maxammo looks like in explorer?

1 Like

thinking of the same thing

might be number values or something

1 Like

screenrec (gyazo.com) ClientGun (Comqts Editing) - Roblox Studio (gyazo.com) ClientGun (Comqts Editing) - Roblox Studio (gyazo.com)

1 Like

Add .Value to the Ammo objects

1 Like

yeah, you’ll have to include .Value to Ammo/MaxAmmo in the script, so that you’re then comparing values instead of instances

like the other guy already said Attempt to compare Instance <= Instance - #2 by hasoco

1 Like

What do you mean by add “.Value”? “.Value” is in there.

1 Like

It isn’t, I added it there.

dsfsdf

something like this

script.Parent.Activated:Connect(function()
	if canshoot and not reloading then
		if script.Parent.Ammo.Value <= script.Parent.MaxAmmo.Value and script.Parent.Ammo.Value > 0 then
			canshoot = false
			Shoot()
			for i,v in pairs (shootpart:GetChildren()) do
				if v:IsA("SpotLight") or v:IsA("ParticleEmitter") then
					v.Enabled = true
					print("Shot")
					wait(0.05)
					v.Enabled = false 
				end
			end
			wait(0.3)
			canshoot = true
		elseif ammo == 0 then
			reload()
			reloading = true
			canshoot = false
			wait(reloadTime)
			reloading = false
			canshoot = true
		end
	end
end)

don’t know what you’re trying to do here though
image

1 Like

This worked! Thanks a bunch, to both of you.

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