Issues with store bought Launchers

Hello Devs! I am trying making a launcher skin store where players can buy skins with in game currency

When i go to buy the launchers from the shop the launchers dont shoot the only gun that shoots is the gun that is given to the player by default. it still makes the sound and everything but no bullet comes out. Also any skins that are animated do not play theyre animation when i buy them from the shop. the guns work outside the shop if i pick them up or put them in the starter pack. but as soon as you put them in replicated storage they dont work.

This is the script i use for all the guns in the game to make them fire.

local tool = script.Parent
local fireEvent = tool.FireEvent
local FastCast = require(tool.FastCastRedux)
local firePoint = tool.OilSpill.FirePoint

local bulletsFolder = workspace:FindFirstChild("BulletFolder") or Instance.new("Folder", workspace)
bulletsFolder.Name = "bulletFolder"
FastCast.VisualizeCasts = true
local bulletTemplate = Instance.new("Part")
bulletTemplate.Anchored = true
bulletTemplate.CanCollide = false
bulletTemplate.Shape = "Ball"
bulletTemplate.Size = Vector3.new(1,1,1)
bulletTemplate.Material = Enum.Material.Metal

local caster = FastCast.new()

local castParams = RaycastParams.new()
castParams.FilterType = Enum.RaycastFilterType.Blacklist
castParams.IgnoreWater =true

local castBehavior = FastCast.newBehavior()
castBehavior.RayCastParams = castParams
castBehavior.Acceleration = Vector3.new(0, -workspace.Gravity, 0)
castBehavior.AutoIgnoreContainer = false
castBehavior.CosmeticBulletContainer = bulletsFolder
castBehavior.CosmeticBulletTemplate = bulletTemplate

local function onEquipped()
	castParams.FilterDescendantsInstances = {tool.Parent, bulletsFolder}
end

local function onLengthChanged(cast,lastPoint, direction, length, velocity, bullet)
	if bullet then
		local bulletLength = bullet.Size.Z/2
		local offset = CFrame.new(0, 0,-(length - bulletLength))
		bullet.CFrame = CFrame.lookAt(lastPoint, lastPoint + direction):ToWorldSpace(offset)
	end
end

local function onRayHit(cast, result, velocity, bullet)
	local hit = result.Instance
	
	
	local character = hit:FindFirstAncestorWhichIsA("Model")
	if character and character:FindFirstChild("Humanoid") then
		character.Humanoid:TakeDamage(100)
	end
	game:GetService("Debris"):AddItem(bullet, .5)
end

local function fire(player, mousePositon)
	local origin =firePoint.WorldPosition
	local direction = (mousePositon- origin).Unit
	caster:Fire(origin, direction, 300, castBehavior)
end

fireEvent.OnServerEvent:Connect(fire)

tool.Equipped:Connect(onEquipped)
caster.LengthChanged:Connect(onLengthChanged)
caster.RayHit:Connect(onRayHit)

This is the script i use to take money from the player and give them the new skin. Oil Spill is the name of the skin in this one.

ocal player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	if player.leaderstats.USD.Value >= 5000 then
		player.leaderstats.USD.Value = player.leaderstats.USD.Value - 5000
		local clonar = game.ReplicatedStorage.OilSpill:Clone()
		clonar.Parent = player.Backpack
	end
end)

If theyre are any other screenshots, videos or codes you would like to see please let me know and ill get them as soon as i can. Thanks for reading.

1 Like

Could you add some debug print lines to your code? Please add the following lines to your code and post the result:

local function onRayHit(cast, result, velocity, bullet)
	local hit = result.Instance
	
	print ("Raycast hit!")
	local character = hit:FindFirstAncestorWhichIsA("Model")
	if character and character:FindFirstChild("Humanoid") then
		print ("Humanoid hit!")
		character.Humanoid:TakeDamage(100)
	end
	game:GetService("Debris"):AddItem(bullet, .5)
	print ("Finish hit!")
end

and this:

local function fire(player, mousePositon)
    print ("Fire event!")
	local origin =firePoint.WorldPosition
	local direction = (mousePositon- origin).Unit
	caster:Fire(origin, direction, 300, castBehavior)
end

This way you might be able to see that the event doesn’t fire in the first place.

1 Like

Try adding the item to the backpack on the server side.
It’s bad practice to have transactions done on the client side.

		local clonar = game.ReplicatedStorage.OilSpill:Clone()
	    clonar.Parent = player.Backpack
1 Like

Wait, is “BulletsFolder” a model or a folder? is that where the bullets are going?

if its a folder they wont show.

edit: i was wrong about this i thought items in folders didnt render for some reason.

1 Like

Bulletfolder is a folder that holds the bullets. Why won’t they show if it’s a folder?

i tried adding those lines and nothing happend. does that mean the event doesnt even happen?

1 Like

If the console doesn’t print anything, it’s very likely the event isn’t fired at all. You might want to check your LocalScript code where the event is fired. If you share it with us, we can help you solve the issue!

this is the local script code it has fire event and a sound that plays. the fireing sound and a realoding sound.

local tool = script.Parent
local player = game:GetService(“Players”).LocalPlayer
local mouse = player:GetMouse()
local FireEvent = tool:WaitForChild(“FireEvent”)
local db = false

tool.Activated:Connect(function()
if db == false then
db = true
local mousePosition = mouse.Hit.Position
script.shoot:Play()

	FireEvent:FireServer(mousePosition)
	wait(.5)--launcher cooldown
	script.reload:Play()
	wait(.5)
	db = false
	end
end)
1 Like

You should probably place the ServerScript somewhere else. I’ve has issues with cloned items and RemoveEvent’s before, and after placing my server script somewhere else it did seem to work. Maybe just add 1 server script that handles all the guns instead of 1 script per gun? Let me know how it goes.

i have each gun set individually to this script how would i go about making one script for them all would i put them all in a folder and make a list of names for the diffrent firePoints?

1 Like

If you take your LocalScript, and in the FireEvent also give script.Parent as a parameter, you can then create 1 Script in ServerStorage. So your create one remote function, one fastcast, etc. and place them inside ReplicatedStorage.

So take this simple for the LocalScript:

local tool = script.Parent
local player = game:GetService(“Players”).LocalPlayer
local mouse = player:GetMouse()
local fireEvent = game.ReplicatedStorage:WaitForChild("FireEvent")
local db = false

tool.Activated:Connect(function()
	if db == false then
		db = true
		
		local mousePosition = mouse.Hit.Position
		script.shoot:Play()
		fireEvent:FireServer(mousePosition, tool)
		wait(.5) --launcher cooldown
		script.reload:Play()
		wait(.5)
		
		db = false
	end
end)

And your server Script:

local fireEvent = game.ReplicatedStorage:WaitForChild("FireEvent")
local FastCast = require(game.ReplicatedStorage.FastCastRedux)

local bulletsFolder = workspace:FindFirstChild("BulletFolder") or Instance.new("Folder", workspace)
bulletsFolder.Name = "bulletFolder"
FastCast.VisualizeCasts = true
local bulletTemplate = Instance.new("Part")
bulletTemplate.Anchored = true
bulletTemplate.CanCollide = false
bulletTemplate.Shape = "Ball"
bulletTemplate.Size = Vector3.new(1,1,1)
bulletTemplate.Material = Enum.Material.Metal

local caster = FastCast.new()

local castParams = RaycastParams.new()
castParams.FilterType = Enum.RaycastFilterType.Blacklist
castParams.IgnoreWater =true

local castBehavior = FastCast.newBehavior()
castBehavior.RayCastParams = castParams
castBehavior.Acceleration = Vector3.new(0, -workspace.Gravity, 0)
castBehavior.AutoIgnoreContainer = false
castBehavior.CosmeticBulletContainer = bulletsFolder
castBehavior.CosmeticBulletTemplate = bulletTemplate

local function onLengthChanged(cast,lastPoint, direction, length, velocity, bullet)
	if bullet then
		local bulletLength = bullet.Size.Z / 2
		local offset = CFrame.new(0, 0, -(length - bulletLength))
		bullet.CFrame = CFrame.lookAt(lastPoint, lastPoint + direction):ToWorldSpace(offset)
	end
end

local function onRayHit(cast, result, velocity, bullet)
	local hit = result.Instance
	
	
	local character = hit:FindFirstAncestorWhichIsA("Model")
	if character and character:FindFirstChild("Humanoid") then
		character.Humanoid:TakeDamage(100)
	end
	game:GetService("Debris"):AddItem(bullet, 0.5)
end

local function fire(player, mousePositon, tool)
	local origin = tool.OilSpill.FirePoint.WorldPosition
	local direction = (mousePositon - origin).Unit
	caster:Fire(origin, direction, 300, castBehavior)
end

fireEvent.OnServerEvent:Connect(fire)

caster.LengthChanged:Connect(onLengthChanged)
caster.RayHit:Connect(onRayHit)

I have not tested this code, but you can try something like this. I don’t really know what some parts do so I can’t help a lot with that but I hope you know what I’m trying to do here. Good luck and feel free to ask if you’re stuck again.

Thank you! I will try it. And post results when I get a chance

1 Like

alright i have put both of these scripts in server storage does that mean i can go to each gun now and delete these scripts from them sense their in serverstorage. also do i need to put a fire event and a remote event in serverstorage as well?

can you screenshot your explorer hierarchy so i can understand where you have these items located

1 Like

You should put a RemoveEvent in ReplicatedStorage and name it FireEvent, and you should place the FastCastRedux module script in ReplicatedStorage. Let me know if this will do the trick!

It’s pretty self explanatory. He has a couple of guns which are tools and each of the tools has a RemoteEvent and the FastCastRedux module script but it would be better to have one event and one module script for all the guns in ReplicatedStorage.

thank you so much for helping me through this very confusing process. this has been very annoying, stressful and confusing and your help is much appreicated. i will try this when i get a chance. thank you for your paticence

1 Like

Good luck. If this doesn’t work either, you could send me a message and I could maybe join you in TeamCreate, or you can send me a copy of the place so I can look at the problem in all detail.

alright thank you i will do my best to try and make this work on my own so i wont have to bug you. but if need be i would love to have you come to TeamCreate and mess around with it

Just message me if you need me and don’t forget to give other’s the solution (or mark it when given) so you can help people having trouble with it in the future :slight_smile: