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

This isn't working in a LocalScript or a normal Script, help?

So basically I'm trying to make it so when a player touches a brick it gives them a box..

This is what I have

function onTouch(hit)
if 6 > 2 then
game.Lighting["Box"]:Clone().Parent = game.Players.LocalPlayer.Backpack
wait(15)
end
end
script.Parent.Touched:connect(onTouch)

It only works in test mode and doesn't work in game... I've tried script and local script.

1 answer

From what I see here it wouldn't ever work in a normal script this way. It calls a LocalPlayer.Backpack which is impossible to call in a normal script.

Your function checks if 6 is bigger than 2 <-- ??, and then assigns the box:Clone() a parent to the local backpack.

From what I can see you want the box to go inside the player's backpack once he hits a certain item.

This is what I recommend:

game.Players.PlayerAdded:connect(function(player)

		script.Parent.Touched:connect(onTouch)

		function onTouch(hit)
			if 6 > 2 then
				local box = game.Lighting["Box"]:Clone()
				box.Parent = player.Backpack
			end
		end
end)

2 comments

0

I tried that and I got a blue underline saying "consider changing it to local" for line 3

0

That is no real issue, it's an error but does not mean the script doesn't work. Consider changing it to local means the variable is only being used once in an enclosed function. ROBLOX simply uses this to tell you you might aswell change the variable to a local variable.

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