Hello, the reason i made this topic because im having a problem with my Shop script(it works fine its just when the player clicks the gui it fires a remotevent sending it to server side where the player would get the weapon but i only want the player to get one of each weapon but the player is still able to get a bunch when your inside the lobby you can choose which weapon you want to use(only bat for now) but if you continue to click on it more bats would show up in your backpack when the match starts script: local OnWeapon = game.ReplicatedStorage.Events.OnWeapon
local hasWeapon = game.ReplicatedStorage.Values.HasWeapon
local Weapons = {
[âBatâ] = game.ReplicatedStorage.Weapons.Bat,
â add more weapons here
}
local weaponName = player.Character.Weapon.Value
if player.Character.HumanoidRootPart:FindFirstChild("Weapons[weaponName]") then
hasWeapon.Value = true
else if not player.Character.HumanoidRootPart:FindFirstChild("Weapons[weaponName]") then
hasWeapon.Value = false
end
end
if Weapons[weaponName] and hasWeapon.Value == false then
local NewWeapon = Weapons[weaponName]:Clone()
NewWeapon.Parent = player.Character.HumanoidRootPart
hasWeapon.Value = true
while wait(0.1) do
if player.Character.InMatch.Value == true then
NewWeapon.Parent = player.Backpack
break
end
end
else
print("can not get another weapon")
-- the player's weapon does not match any weapon in the Weapons table
end
the problem is if you were to click the bat gui from the shop it will show up in the hp(humanoidRootPart) but when you click it multiple times a bunch will show which i only want one of that weapon.
if player.Character.HumanoidRootPart:FindFirstChild("Weapons[weaponName]") then
hasWeapon.Value = true
else if not player.Character.HumanoidRootPart:FindFirstChild("Weapons[weaponName]") then
hasWeapon.Value = false
end
end
Because youâre FindFirstChild(âWeapons[weaponName]â) so the script will find object that have a name âWeapons[weaponName]â to fix this you should use:
if player.Character.HumanoidRootPart:FindFirstChild(Weapons[weaponName]) then
hasWeapon.Value = true
elseif not player.Character.HumanoidRootPart:FindFirstChild(Weapons[weaponName]) then
hasWeapon.Value = false
end
end
also elseif statement should be call as elseif not else if.
03:59:49.935 Argument 1 missing or nil - Server - GivePlayerWeapon:13 when I remove the quotes this occurs, I tried remaking that whole section, but this is all I got.
Maybe your weaponName variable just got nil value did you set value of your player.Character.Weapon.Value in local script? if yes then you need to set the value with server script or else server script will see it be nil
if player.Character.HumanoidRootPart:FindFirstChild(Weapons[weaponName].Name) then
hasWeapon.Value = true
elseif not player.Character.HumanoidRootPart:FindFirstChild(Weapons[weaponName].Name) then
hasWeapon.Value = false
end
also can you tell me whatâs the value of weaponName?
finally, I figured it outđ so instead of using the if and elseif statement i did this local OnWeapon = game.ReplicatedStorage.Events.OnWeapon
local hasWeapon = game.ReplicatedStorage.Values.HasWeapon
local Weapons = {
[âBatâ] = game.ReplicatedStorage.Weapons.Bat,
â add more weapons here
}
local weaponName = player.Character.Weapon.Value
--if player.Character.HumanoidRootPart:FindFirstChild(Weapons[weaponName]) then
-- hasWeapon.Value = true
â elseif not player.Character.HumanoidRootPart:FindFirstChild(Weapons[weaponName]) then
â hasWeapon.Value = false
âend
print(Weapons[weaponName])
if Weapons[weaponName] and not player.Character.HumanoidRootPart:FindFirstChild(weaponName) then
print(hasWeapon.Value)
local NewWeapon = Weapons[weaponName]:Clone()
NewWeapon.Parent = player.Character.HumanoidRootPart
hasWeapon.Value = true
while wait(0.1) do
if player.Character.InMatch.Value == true then
NewWeapon.Parent = player.Backpack
break
end
end
âelseif not player.Character.HumanoidRootPart:FindFirstChild(âWeapons[weaponName]â) then
âhasWeapon.Value = false
âprint(Weapons[weaponName])
â the playerâs weapon does not match any weapon in the Weapons table
end
end)
which caused it to work! thank you for your help!