Hello, I have a problem with script.
-
What do you want to achieve? I want to make it so that when a person shoots a weapon, the type of bullet is selected. I’m trying to make this with Event.
-
What is the issue? I’m every time getting this error when I testing.
-
What solutions have you tried so far? I looked in the Developer Hub and found nothing.
Here’s the scripts, that I tried to make.
Server Script:
rs.Remotes.Events:WaitForChild("Shoot").OnServerEvent:Connect(function(player, muzzlePos, mousePos, bulletType)
if player.Character then
local sound = player.Character.Torso:FindFirstChild("FireSound")
if sound then
sound:Play()
end
local bullet = rs.Bullets[bulletType]:Clone() -- error
bullet.Name = "Bullet"
bullet.Parent = workspace
bullet.CanCollide = false
bullet.Anchored = true
bullet.CFrame = CFrame.new(muzzlePos, mousePos)
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Parent = bullet
end
end)
Local Script:
local framework = {
inventory = {
"M4A1";
"M9";
"Knife";
"Frag";
};
module = nil;
viewmodel = nil;
currentSlot = 1;
}
function shoot()
if framework.module.fireMode == "Semi" then
fireAnim:Play()
framework.module.ammo -= 1
rs.Remotes.Events:WaitForChild("Shoot"):FireServer(framework.viewmodel.Muzzle.Position, mouse.Hit.p, framework.module.bulletType)
debounce = true
wait(framework.module.debounce)
debounce = false
elseif framework.module.fireMode == "Full Auto" then
isShooting = true
end
end
Module Script:
local Settings = {
canAim = true;
aimSmooth = .15;
fireAnim = "rbxassetid://11582704656";
fireSound = game.ReplicatedStorage.Sounds.M4A1.Fire;
bulletType = "Machine";
watchAnim = "rbxassetid://11588898523";
sprintCF = CFrame.new(0, 0, 0) * CFrame.Angles(math.rad(-90/5), math.rad(45/5), math.rad(75/5));
canSemi = true;
canFullAuto = true;
ammo = 30;
maxAmmo = 30;
debounce = .81;
reloadTime = 3;
fireMode = "Full Auto";
fireRate = .07;
}
return Settings
If someone know solution for this error, then please help me.
Thank you.