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

Script only works inside ROBLOX Studio but not in online?

I recently made a script where when you click on a gun it gets duplicated into your backpack. This is the script i made.

function onClicked()
	game.Lighting["Remington 870"]:Clone().Parent = game.Players.LocalPlayer.Backpack
end
    
    script.Parent.ClickDetector.MouseClick:connect(onClicked)



But the problem is it works perfectly fine in roblox studio, but when i save and go online it doesn't work. Can someone help me or explain to me why this is happening? Thank you :)

1 answer

game.Players.LocalPlayer

That can only be accessed from a LocalScript. Assuming you aren't using FilteringEnabled, try this in a normal script (still inside the ClickDetector):

function onClicked(Clicker) 
	game.Lighting["Remington 870"]:Clone().Parent = Clicker.Backpack 
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

3 comments

0

I put that code inside of a normal script but nothing happened though?

0

Try putting the script in ServerScriptService. Also, I recommend putting the shotgun and other stuff that you want to store in ReplicatedStorage.

0

Still not working

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