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)
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, LocalScript
s 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.