Help with alvinblox script please idk what"s happening? [closed]
Please provide code with your answers. Simply posting an explanation does not help someone new to programming understand how to implement a concept programatically.
So I have this alvinblox script
001 | local serverStorage = game:GetService(“ServerStorage”) |
002 | local replicatedStorage = game:GetService(“ReplicatedStorage”) |
003 | local KOValue = “Kills” |
004 | local WOValue = “Wipeouts” |
006 | replicatedStorage.ShootEvent.OnServerEvent:Connect( function (player,tool,position,part) |
007 | if game.Workspace [ player.Name ] .Humanoid.Health < = 0 then |
008 | — The player is dead, do not do anything |
010 | local distance = (tool.Handle.CFrame.p – position).magnitude |
011 | if game.Workspace:FindFirstChild(player.Name..“‘s Trajectory”) then |
012 | game.Workspace:FindFirstChild(player.Name..“‘s Trajectory”):Destroy() |
014 | local trajectory = Instance.new(“Part”,game.Workspace) |
015 | local smoke = serverStorage.SmokeParticle:Clone() |
016 | smoke.Parent = tool.Handle |
017 | trajectory.BrickColor = BrickColor.new(“Institutional white”) |
018 | trajectory.Material = “SmoothPlastic” |
019 | trajectory.Name = player.Name..“‘s Trajectory” |
020 | trajectory.Transparency = 0.5 |
021 | trajectory.Anchored = true |
022 | trajectory.Locked = true |
023 | trajectory.CanCollide = false |
024 | trajectory.Size = Vector 3. new( 0.3 , 0.3 ,distance) |
025 | for i = 0 ,distance, 6 do |
026 | trajectory.CFrame = CFrame.new(tool.Handle.CFrame.p,position) * CFrame.new( 0 , 0 ,-distance / 2 ) |
031 | if part.Name = = “Head” or part:IsA(“Hat”) and part.Parent:FindFirstChild(“Humanoid”).Health > 0 then |
033 | replicatedStorage.Headshot:FireClient(player) |
036 | local humanoid = part.Parent:FindFirstChild(“Humanoid”) |
038 | humanoid = part.Parent.Parent:FindFirstChild(“Humanoid”) |
040 | humanoid:TakeDamage(damage) |
041 | if humanoid.Health < = 0 then |
042 | player.leaderstats [ KOValue ] .Value = player.leaderstats [ KOValue ] .Value + 1 |
043 | game.Players [ humanoid.Parent.Name ] .leaderstats [ WOValue ] .Value = game.Players [ humanoid.Parent.Name ] .leaderstats [ WOValue ] .Value + 1 |
054 | replicatedStorage.EquipAnimation.OnServerEvent:Connect( function (player,animation) |
055 | local newAnim = game.Workspace [ player.Name ] .Humanoid:LoadAnimation(animation) |
057 | replicatedStorage.UnequipAnimation.OnServerEvent:Connect( function (player,animation) |
059 | for i,v in pairs (game.Workspace:GetChildren()) do |
060 | if v.Name = = player.Name..“‘s Trajectory” then |
065 | replicatedStorage.Reload.OnServerEvent:Connect( function (player,animation) |
067 | local reloadAnim = game.Workspace [ player.Name ] .Humanoid:LoadAnimation(animation) |
072 | function checkBodyType(player,tool) |
073 | if game.Workspace [ player.Name ] :FindFirstChild(“LowerTorso”) then — R 15 |
078 | if game.Workspace [ player.Name ] :FindFirstChild(“Torso”) then — R 6 |
084 | replicatedStorage.CheckBodyType.OnServerInvoke = checkBodyType |
086 | — Local Script, which goes inside the tool |
088 | local tool = script.Parent — Getting the tool |
089 | local player = game:GetService(“Players”).LocalPlayer — Getting the player |
090 | local mouse = player:GetMouse() — Getting the mouse |
091 | local sound = tool:WaitForChild(“Gunfire”) |
092 | local torso = “” — Nothing for now. |
093 | local reloading = false — Variable to check if we are currently reloading |
094 | local contextActionService = game:GetService(“ContextActionService”) — Allow us to cater for Mobile players |
095 | local bodytype = nil — Nil for now but will check whether player is R 6 or R 15 |
096 | local difference = 0 — Difference between position of head and mouse |
097 | local replicatedstorage = game:GetService(“ReplicatedStorage”) |
098 | local gungui = tool:WaitForChild(“GunGUI”) |
099 | local bullets = tool:WaitForChild(“Bullets”) |
102 | local equipAnimation = replicatedstorage:WaitForChild(“EquipAnimation”) |
103 | local headshot = replicatedstorage:WaitForChild(“Headshot”) |
104 | local reload 2 = replicatedstorage:WaitForChild(“Reload”) |
105 | local shootevent = replicatedstorage:WaitForChild(“ShootEvent”) |
106 | local unequipanimation = replicatedstorage:WaitForChild(“UnequipAnimation”) |
108 | local checkBodyType = replicatedstorage:WaitForChild(“CheckBodyType”) |
109 | local fetchBulletsLeft = replicatedstorage:WaitForChild(“FetchBulletsLeft”) |
111 | function findBodyType() — Used to determine whether a player is R 6 or R 15 |
112 | bodytype = checkBodyType:InvokeServer(tool) — Invoking the Remotefunction to do a check on the server |
118 | reload 2 :FireServer(tool.reload) |
120 | player.PlayerGui:WaitForChild(“GunGUI”).Bullets.Text = “Reloading!” |
123 | player.PlayerGui:WaitForChild(“GunGUI”).Bullets.Text = “Bullets: “..bullets.Value |
125 | equipAnimation:FireServer(tool.shoot) |
128 | — When the tool is equipped, the following event will run |
129 | tool.Equipped:Connect( function (mouse) |
130 | gungui:Clone().Parent = player.PlayerGui — We are cloning the Gun GUI into the player’s PlayerGUI |
131 | findBodyType() — Calling the function above to check the body type . |
132 | equipAnimation:FireServer(tool.shoot) — Calling the equip animation remoteevent so that the server can play the animation |
134 | mouse.Button 1 Down:Connect( function () |
135 | if bullets.Value < = 0 or reloading = = true then |
138 | local head = game.Workspace [ player.Name ] .Head.CFrame.lookVector |
139 | local mouse = CFrame.new(game.Workspace [ player.Name ] .Head.Position,mouse.Hit.p).lookVector |
140 | difference = (head–mouse) |
141 | local ray = Ray.new(tool.Handle.CFrame.p,(player:GetMouse().Hit.p – tool.Handle.CFrame.p).unit* 300 ) |
142 | local part,position = game.Workspace:FindPartOnRay(ray,player.Character, false , true ) |
144 | if difference.magnitude < 1.33 then |
145 | shootevent:FireServer(tool,position,part) |
146 | bullets.Value = bullets.Value – 1 |
150 | local reloadMobileButton = contextActionService:BindAction(“ReloadBtn”,reload, true ,“r”) |
151 | contextActionService:SetPosition(“ReloadBtn”,UDim 2. new( 0.72 ,– 25 , 0.20 ,– 25 )) |
154 | tool.Unequipped:Connect( function () |
156 | unequipanimation:FireServer(tool.shoot) |
157 | player.PlayerGui.GunGUI:Destroy() |
158 | contextActionService:UnbindAction(“ReloadBtn”) |
160 | headshot.OnClientEvent:Connect( function () |
161 | player.PlayerGui.GunGUI.Headshot:TweenPosition(UDim 2. new( 0.5 ,– 100 , 0.5 ,– 25 ), “Out”,“Quint”, 0.3 ) |
163 | player.PlayerGui.GunGUI.Headshot:TweenPosition(UDim 2. new(– 1 , 0 , 0.5 ,– 25 ), “In”,“Quint”, 0.4 ) |
165 | player.PlayerGui.GunGUI.Headshot.Position = UDim 2. new( 1.5 , 0 , 0.5 ,– 25 ) |
169 | — Leaderboard code which goes inside ServerScriptService, optional to include, you can add your own if you want but bear in mind the gun won’t work unless you have some sort of leaderboard with a Kills and Wipeouts stat |
171 | game.Players.PlayerAdded:Connect( function (player) |
172 | local leaderstats = Instance.new(“IntValue”,player) |
173 | leaderstats.Name = “leaderstats” |
175 | local kills = Instance.new(“IntValue”,leaderstats) |
179 | local wipeouts = Instance.new(“IntValue”,leaderstats) |
180 | wipeouts.Name = “Wipeouts” |
183 | — Data saving code goes here if you need it |
186 | This was a lengthy tutorial from me, my longest yet! If you want to watch more tutorials on how to script on Roblox, remember to subscribe to my channel. |
but it doesn't work, help please
thanks