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

A button script works in Studio, but not in actual ROBLOX. Its a nil value? {UPDATE}

I was recently working on a class selection GUI, and I encountered this problem. "Thompson" is a nil value. Ive never had this problem before. The thing is, it works in Studio but then it errors inside actual ROBLOX?

Heres the code, Ill also link some picture to Imgur that give a more info in case you need it :)

player = game.Players.LocalPlayer
button = script.Parent.Play

button.MouseButton1Click:connect(function()
	local Thompson = game.Workspace.Guns:findFirstChild("Thompson")
	Thompson:clone().Parent = player.Backpack
	Thompson:clone().Parent = player.StarterGear
	player.HasClass.Value = true
	script.Parent.Visible = false
end)

You'll have to manually copy the link

https://imgur.com/FnlC69V

^Shows were it is in Explorer

https://imgur.com/7FkZMyy

^Shows the error inside actual ROBLOX

Thanks and I hope somoene may be able to figure this out :)

ADDON - I tried using, Lighting, Replicated Storage and Server Storage. Lighting and Replicated storage work but then the gun just falls through the map and doesnt stay in the hand. Its weirdd

ADDON 2 - It works when FE is turned off but it doesnt work with FE turned on? Any new ideas?

1 comment

0

instead of using workspace I would use replicated storage

2 answers

  1. Make sure "Thompson" is in the Guns folder
  2. Use "ReplicatedStorage" to hold any items you want to clone. So move the "Guns" from workspace to ReplicatedStorage

Theres an easier way to clone things in coding, such as using this :

local player = game.Players.LocalPlayer
local button = script.Parent.Play
local rep = game:GetService("ReplicatedStorage")

button.MouseButton1Click:Connect(function()
rep.Guns:FindFirstChild("Thompson"):Clone().Parent = player.Backpack
player.HasClass.Value = true
script.Parent.Visible = false
end)

You was changing the parent of the gun, 2 times. Starterpack and Startergear, which i never heard of startergear.

What i wrote should work, if any errors feel free to comment.

12 comments

0

Oh I forgot the "GetService" part. I forgot you needed that, my bad.

0

If it did work, please accept

0

Also I used StarterGear because on death things get removed from your backpack so I needed startergear to keep it there over death.

0

True, but you can add in a 'CharacterAdded' function so it clones when respawned

0

Nope it doesnt work. The gun still falls through the world XD

0

Do you want to clone it? Or something else?

0

Basically I want to when a player picks the class it will give them the gun.

0

Wait dude it works with FE turned off. But when I turn it on it doesnt work... Any Ideas?

0

Need to use a RemoteEvent and fire the server when you call the clone so it can clone in the players inventory. If you want an example lemme know so i can update the script.

0

Yeah can I have an example, I am a little confused. :)

0

I figured it out YBN, I just watched a SteadyOn tutorial and I got it working. I used a remoteevent

0

Alright good

Try using a local script if your not already using one.

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