Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Error when trying to access a part using string values?

So UpgradeWeapon is a stringvalue and this is my script in serverscriptservice. Why does it return this error? How can I access the part?

ServerScriptService.Upgrade Handler.Main:12: invalid argument #2 (string expected, got Instance)


local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage:WaitForChild("UpgradeEvent")


local function upgrade(player,UpgradeWeapon,UpgradeAmount)
	
	local Weapon = UpgradeWeapon
	
	print ("Upgrade Event Recieved")
	
	player.Inventory[Weapon].Damage.Value = player.Inventory[UpgradeWeapon].Damage.Value + UpgradeAmount
	
	


	end


remoteEvent.OnServerEvent:Connect(upgrade)

1 comment

0

Could you give the local script that fires the event bc we dont know what the variables are without it.

2 answers

try changing

player.Inventory[Weapon].Damage.Value = player.Inventory[UpgradeWeapon].Damage.Value + UpgradeAmount

to

player.Inventory[Weapon].Damage.Value = player.Inventory[UpgradeWeapon].Damage.Value + UpgradeAmount.Value

the error is in line 12, and it is happening because you're giving an instance not a string

2 comments

0

Such a simple solution, and yet the most common mistake we make when working with values.

0

It does not work it gives the same error. It expects a string but gets an instance why?

-- Pretty sure you are firing the actual tool instead of the name of the tool. try 

local Weapon = tostring(UpgradeWeapon)
player.Inventory[Weapon].Damage.Value += tonumber(UpgradeAmount)

2 comments

0

well that fixed that error but now I have a new error for some reason it is sending upgradeweapon as my username even though the value isnt my username so its searching for "epicnmac" and says that im not part of the folder when it should be searching for the upgradeweapon

0

uh it probably in the local script then. I think ur firing your player? uh could u send the local script as well?

This discussion is preserved as it was. New answers, comments, and votes are closed.