Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

gun click to pickup script not working?

Asked by
Nozazxe 107
3 years ago

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)
0
Did you get any errors in the output? Neatwyy 123 — 3y
0
.Nope Nozazxe 107 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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.

0
the script in the gun in workspace is a local script. Will that still work? Nozazxe 107 — 3y
0
Sorry I am incorrect, I forgot about a few things, I am editing an answer rn MrSuperKrut 167 — 3y
Ad

Answer this question