I can't get my dart script to create a mesh. How would I do this?
Hi everyone. I am trying to script a dart gun for a game I'm working on. The gun uses some simple remote events to communicate client to server.
The local script tests to see if the tool is equipped and is supposed to fire server. The server reads this and creates the dart projectile and mesh.
Then the local script sends another signal when the tool is clicked to clone the mesh.
Local script below:
IGNORE VARIABLES
02 | local IgnoreList = { rocket = 0 , handle = 1 , effect = 1 , water = 1 } |
05 | local tool = script.Parent |
07 | local player = game.GetService( "Players" ).LocalPlayer |
09 | local mouse = player:GetMouse() |
11 | local configs = game.ReplicatedStorage.MaverickConfigurations |
12 | local gungui = tool:WaitForChild( "GunGUI" ) |
13 | local firesound = tool.WaitForChild( "FireSound" ) |
14 | local reloadsound = tool.WaitForChild( "ReloadSound" ) |
15 | local primesound = tool.WaitForChild( "PrimeSound" ) |
16 | local reloading = false |
20 | local capacity = configs.Capacity.Value |
22 | local gravityacceleration = 196.2 |
26 | local meshscale = Vector 3. new( 0.17 , 0.17 ,. 25 ) |
28 | local dartpartscale = Vector 3. new( 1 , 1 , 1 ) |
30 | local dartcolor = BrickColor.new( 33 , 60 , 122 ) |
32 | local spawnPosition = tool.Model.Muzzle.CFrame() |
41 | local replicatedstorage = game:GetService( "ReplicatedStorage" ) |
43 | local gungui = tool:WaitForChild( "GunGUI" ) |
46 | local equipAnimation = replicatedstorage:WaitForChild( "EquipAnimation" ) |
48 | local unequipanimation = replicatedstorage:WaitForChild( "UnequipAnimation" ) |
50 | local primeAnimation = replicatedstorage:WaitForChild( "PrimeAnimation" ) |
52 | local shootevent = replicatedstorage:WaitForChild( "ShootEvent" ) |
54 | local prime = replicatedstorage:WaitForChild( "Prime" ) |
56 | local reload = replicatedstorage:WaitForChild( "Reload" ) |
58 | local equip = replicatedstorage:WaitForChild( "Equip" ) |
60 | local headshot = replicatedstorage:WaitForChild( "Headshot" ) |
62 | local checkBodyType = replicatedstorage:WaitForChild( "CheckBodyType" ) |
64 | local fetchRemainingAmmo = replicatedstorage:WaitForChild( "FetchRemainingAmmo" ) |
68 | tool.Equipped:Connect( function (mouse) |
69 | replicatedstorage.equip:FireServer(mouse) |
70 | gungui:Clone().Parent = player.PlayerGui |
71 | equipAnimation:FireServer(tool.shoot) |
76 | local function OnActivated() |
77 | if reloading = = true or priming = = true |
81 | replicatedstorage.ShootEvent:FireServer(spawnPosition,tool) |
Server Script:
06 | local player = game.Players.LocalPlayer |
07 | local replicated = game:GetService( "ReplicatedStorage" ) |
08 | local configs = replicated:WaitForChild( "MaverickConfigurations" ) |
09 | local coolDown = configs.AttackCooldown.Value |
11 | local reloadtime = configs.ReloadTime.Value |
12 | local dartspeed = configs.DartSpeed.Value |
14 | local meshscale = Vector 3. new( 0.35 , 0.35 , 0.25 ) |
15 | local dartsize = Vector 3. new( 1.2 , 1.2 , 3.27 ) |
19 | game.ReplicatedStorage.MaverickConfigurations.Equip.OnServerEvent:Connect( function (player, mouse) |
21 | local Dart = Instance.new( 'Part' ) do |
24 | Dart.FormFactor = Enum.FormFactor.Custom |
26 | Dart.CanCollide = false |
29 | local mesh = Instance.new( 'SpecialMesh' , Dart) |
30 | mesh.MeshId = dartmesh |
31 | mesh.Scale = meshscale |
34 | local bodyForce = Instance.new( 'BodyForce' , Dart) |
35 | bodyForce.Name = 'Antigravity' |
36 | bodyForce.force = Vector 3. new( 0 , Dart:GetMass() * Gravity, 0 ) |
45 | game.ReplicatedStorage.MaverickConfigurations.ShootEvent.OnServerEvent:Connect( function (player,spawnPosition,tool) |
47 | local dartClone = Dart:Clone() |
49 | dartClone.BrickColor = BrickColor.new( 33 , 60 , 122 ) |
51 | dartClone.CFrame = CFrame.new(spawnPosition, target) |
52 | dartClone.Velocity = dartClone.CFrame.lookVector * dart_SPEED |
53 | dartClone.Parent = game.Workspace |
55 | delay(coolDown, function () |
61 | if dartClone then dartClone:Destroy() |
Thanks for your help everyone!