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

attempt to index local 'hotsword' (a nil value)?

Hello, I am trying to give myself a sword called "Hot" using a LocalScript in StarterGui. The so called weapon is inside ServerStorage. This is the code:

local hotsword = game.ServerStorage:FindFirstChild("Hot")
local clonedHotSword = hotsword:Clone()
clonedHotSword.Parent = player.Backpack

Whenever I test the game, I get the following error: Players.Xrp200.PlayerGui.LocalScript:190: attempt to index local 'hotsword' (a nil value) ^I have no idea what the error means^

I have tried this with WaitForChild() but then it would give me a warning: Infinite yield possible on 'ServerStorage:WaitForChild("Hot")' And ends up never giving me the sword.

I'm a beginner at scripting and I can't seem to fix this issue properly, please help.. thanks.

8 comments

0

Put the Model inside of the "ReplicatedStorage" and get it from there.

0

it has nothing to do with that he just diddnt make a variable for player

0

and u might wanna use a if statement

0

I have tried putting it in ReplicatedStorage, I got the weapon but the sword falls apart whenever I equip it. I have made the variable for player, it's just that I didn't put everything so that it's easier to read guess?

0

Or is that actually a whole different error/my fault?

1

Taco, When i'm in roblox studio and i put stuff inside of the serverstorage and then if i test play it removes from the ServerStorage.

0

Same! Everything inside ServerStorage dissepears!

0

Yea, That's why it says "Nil", Because it won't find the model in the ServerStorage.

1 answer

✓ Accepted answer
local hotsword = game.ReplicatedStorage:FindFirstChild("Hot")
local clonedHotSword = hotsword:Clone()
clonedHotSword.Parent = player.Backpack

2 comments

0

Alright thank you

0

Explain the script.

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