Hello!
I was making a gun for my game, it has 1 local script called front end and 1 script called back end, and I finished coding them, but for some reason it doesn't work, could someone tell me what made it not working?
The tool contains:
Local Script "Front End"
Script "Back End"
Remote Event "OnShoot"
Union "Handle"
Part "Shoot"
The Server Storage contains:
ParticleEmitter "BulletsEffect" (has an asset)
Part "Bullet"
Part "Hole"
The Replicated Storage contains:
Remote Event "RayCastEvent"
Here is the local script:
local tool = script.Parent local maxammo = 1 local ammo = maxammo local reloading = false local UIS = game.GetService("UserInputService") local remote = tool:WaitForChild("OnShoot") local players = game:GetService("Players") local client = players.LocalPlayer local cursor = client:GetMouse() local camera = game.Workspace.CurrentCamera local anim = Instance.new("Animation") local strplr = game:GetService("StarterPlayer") anim.AnimationId = "rbxassetid://7156099342" local track = "rbxassetid://7156099342"-- idle anim local reloadanim = Instance.new("Animation") reloadanim.AnimationId = "rbxassetid://7155833121" local trackreload -- reload animation tool.Activated:Connect(function() if ammo > 0 and not reloading then ammo = ammo - 1 camera.CFrame = camera.CFrame * CFrame.Angles(0,math.rad(3),0) remote:FireServer(cursor.Hit.Position) else local sound = Instance.new("Sound", tool) sound.SoundId = "rbxassetid://132464034" sound.EmitterSize = 30 sound:Play() -- plays the no ammo sound end end) tool.Equipped:Connect(function() local function reload() -- Sounds/Anims local sound = Instance.new("Sound",tool) sound.SoundId = "rbxassetid://4808446768" sound.EmitterSize = 30 sound:Play() trackreload = script.Parent.Parent.Humanoid:LoadAnimation(reloadanim) trackreload.Priority = Enum.AnimationPriority.Movement -- The animation priority is movement trackreload.Looped = false track:Stop() trackreload:Play() -- Reload reloading = true wait(3) track:Play() ammo = maxammo -- fills the magazine reloading = false end UIS.InputBegan:Connect(function(Key) if Key.KeyCode == Enum.KeyCode.R and reloading == false and ammo ~= maxammo then reload() end end) end) tool.Unequipped:Connect(function() if track then track:Stop() end end)
And here is the script:
local tool = script.Parent local shoot_part = tool.WaitForChild("Shoot") local remote = tool:WaitForChild("OnShoot") local WorkSpace = game:GetService("Workspace") local ServerStorage = game:GetService("ServerStorage") local UIS = game:GetService("UserInputService") remote.OnServerEvent:Connect(function(player,position) local sound = Instance.new("Sound") sound.SoundId = "rbxassetid://1590181673" sound.EmitterSize = 30 sound:Play() local origin = shoot_part.Position local direction = (position - origin).Unit*300 local result = WorkSpace:Raycast(origin, direction) local intersection = result and result.Position or origin + direction local distance = (origin - intersection).Magnitude local particle_clone = ServerStorage.BulletEffect particle_clone.Parent = shoot_part local bullet_clone = ServerStorage.Bullet:Clone() bullet_clone.Size = Vector3.new(0.3,0.3,distance) bullet_clone.CFrame = CFrame.new(origin, intersection)*CFrame.new(0,0,-distance/2) bullet_clone.Parent = WorkSpace local hole_clone = ServerStorage.Hole:Clone() hole_clone.Size = Vector3.new(0.3,0.3,0.3) hole_clone.CFrame = CFrame.new(intersection)*CFrame.new(0,0,-intersection/2) hole_clone.Parent = WorkSpace if result then -- Checks the results of the ray local part = result.Instance local humanoid = part.Parent:FindFirstChild("Humanoid") or part.Parent.Parent:FindFirstChild("Humanoid") local head = part.Parent:FindFirstChild("Humanoid") and part.Parent.Parent:FindFirstChild("Head") if head then hole_clone:Destroy() humanoid:TakeDamage(200) end if humanoid then hole_clone:Destroy() humanoid:TakeDamage(50) end end wait(0.25) particle_clone:Destroy() bullet_clone:Destroy() wait(7) hole_clone:Destroy() end)
Could someone tell me where is the error, are those scripts outdated and needs modifications?
Thanks in advance