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

Clone a filtering enabled gun? please help

Hello people hope your having a great day but i ran into a problem im making a gun game script but when i make it when you get a kill you get a new gun you get the gun but you cant use it (Im using a super complex gun here is a model: https://www.roblox.com//library/2273555208/asset)

And here is the script im using for the kill thing


wait(2)

script.Parent.Parent.leaderstats.Kills.Changed:Connect(function()
	wait()
	local choose = math.random(1,22)
	local gun = game.ReplicatedStorage['Gun'..choose]:Clone()
	gun.Parent = script.Parent
	end)


The LOCAL script is in the starterpack

Please help

AND

If you want to be nice i'm having a other problem as well here: https://scriptinghelpers.org/questions/82061/animation-does-not-play-in-clone-npc

So please help please

1 answer

✓ Accepted answer

You need to use a local script and server script to do this first of all you need to start off by creating a RemoteEvent in replicated storage then in a local script you need to fire this remote event with the arguments containing the guns name after this you create a server script which is the listener for the RemoteEvent and you need to find the gun from replicated storage and clone the gun into the players backpack this is how you would do it.

-- LocalScript
local Remote = game:GetService('ReplicatedStorage'):WaitForChild('GunClone')
local leaderstats = game.Players.LocalPlayer:WaitForChild('leaderstats')

leaderstats.Kills.Changed:Connect(function()
    wait()
    local choose = math.random(1,22)
    local gun = 'Gun'..choose
    print(gun)
    Remote:FireServer(gun)  
end)

Server

-- ServerScript
local Remote = game:GetService('ReplicatedStorage'):WaitForChild('GunClone')

Remote.OnServerEvent:Connect(function(player,gun)
local ChosenGun = game.ReplicatedStorage:WaitForChild(gun):Clone()
ChosenGun.Parent = player:WaitForChild('Backpack')
end)

The local script should be positioned in StarterGui and the ServerScript should be positioned in ServerScriptService

You can learn more about Filtering Enabled by clicking the link below

https://www.youtube.com/watch?v=_jTd4sfCh7Y

2 comments

0

THANK YOU SO MUCH

0

Np

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