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

gun click to pickup script not working?

Hi. so i made it so if you click a gun object, it gives you the gun. But it does not work. Why? Script in serverscriptservice

local events = game.ReplicatedStorage.GunEvents
local guns = game.ReplicatedStorage.Guns
events.AR48.OnServerEvent:Connect(function(player)
		local gun = guns.Rifle.AR48:Clone()
	gun.Parent = player.Backpack
	print("got gun!")
end)

script in gun

script.Parent.MouseClick:Connect(function()
	local event = game.ReplicatedStorage.GunEvents.AR48
	event:FireServer()
	print("fired")
end)

2 comments

0

Did you get any errors in the output?

0

.Nope

1 answer

Edited since my previous answer was incorrect. A LocalScript is not working everywhere. Read this to learn why and where you need a local script. Since a gun is not a client-only object and located in the workspace, LocalScripts aren't gonna work there like there is nothing in there. Instead, you need to change a script's location which is in the gun. If you are unsure where this script should be, just put the script in the StarterPlayer.StarterPlayerScripts. Also you need to modify a script a little bit.

workspace.gun.ClickDetector.MouseClick:Connect(function()
	local event = game.ReplicatedStorage.GunEvents.AR48
	event:FireServer()
	print("fired")
end)

Try this and write a comment if something is wrong.

2 comments

0

the script in the gun in workspace is a local script. Will that still work?

0

Sorry I am incorrect, I forgot about a few things, I am editing an answer rn

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