Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Error when trying to access a part using string values?

Asked by 3 years ago
Edited 3 years ago

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)
0
Could you give the local script that fires the event bc we dont know what the variables are without it. BulletproofVast 1033 — 3y

2 answers

Log in to vote
2
Answered by 3 years ago

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

0
Such a simple solution, and yet the most common mistake we make when working with values. radiant_Light203 1166 — 3y
0
It does not work it gives the same error. It expects a string but gets an instance why? epicnmac 63 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
-- 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)
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 epicnmac 63 — 3y
0
uh it probably in the local script then. I think ur firing your player? uh could u send the local script as well? BulletproofVast 1033 — 3y

Answer this question