Hi Everyone,
My bro and I have been trying to learn to script roblox. We started first on a bunch of tutorials that were using deprecated code, and using books with deprecated code. After we figured that out - we started searching for newer tutorials.
Enter AlvinBlox - so we start working on his "Make a Gun" tutorial.
We grabbed code directly from his website at: https://www.alvinblox.com/roblox-gun-tutorial-code/ and plugged it into the folders he specifies.
We made our animations. We did the whole thing.
For some reason when we test on our home server with 2 players, it goes like this:
**You enable his gun, it appears in his hand for 5 or 10 seconds. Then it disappears. It also Disappears from inventory.
OK, so I thought "Hey, reset the player, and see what happens.
After resetting the player, I tried readying the gun. It equips, and it does not unequip this time.
**
That's weird.
Any help?, We';d humbly appreciate it.
--Local Script here
local tool = script.Parent -- Getting the tool
local player = game:GetService("Players").LocalPlayer -- Getting the player
local mouse = player:GetMouse() -- Getting the mouse
local sound = tool:WaitForChild("Gunfire")
local torso = "" -- Nothing for now.
local reloading = false -- Variable to check if we are currently reloading
local contextActionService = game:GetService("ContextActionService") -- Allow us to cater for Mobile players
local bodytype = nil -- Nil for now but will check whether player is R6 or R15
local difference = 0 -- Difference between position of head and mouse
local replicatedstorage = game:GetService("ReplicatedStorage")
local gungui = tool:WaitForChild("GunGUI")
local bullets = tool:WaitForChild("Bullets")
local reloadtime = 3
-- Remote Events
local equipAnimation = replicatedstorage:WaitForChild("EquipAnimation")
local headshot = replicatedstorage:WaitForChild("Headshot")
local reload2 = replicatedstorage:WaitForChild("Reload")
local shootevent = replicatedstorage:WaitForChild("ShootEvent")
local unequipanimation = replicatedstorage:WaitForChild("UnequipAnimation")
-- Remote Functions
local checkBodyType = replicatedstorage:WaitForChild("CheckBodyType")
local fetchBulletsLeft = replicatedstorage:WaitForChild("FetchBulletsLeft")
-- Find Body Type
function findBodyType() -- Used to determine whether a player is R6 or R15
bodytype = checkBodyType:InvokeServer(tool) -- Invoking the Remotefunction to do a check on the server
print(bodytype)
end
-- Reloading function
function reload()
--debounce variable
reloading = true
--fire remote event on server, and the argument in () tells which animation to fire as well
reload2:FireServer(tool.reload)
--changes mouse icon during reload
mouse.Icon = "http://www.roblox.com/asset?id=10952419"
--changes text inside gunGUI to read 'reloading'
player.PlayerGui:WaitForChild("GunGUI").Bullets.Text = "Reloading!"
--sets a wait equals to 3 seconds as defined at top
wait(reloadtime)
--restocks bullets by changing global number value
bullets.Value = 6
--change text in gunGUI back to read bullet count again
player.PlayerGui:WaitForChild("GunGUI").Bullets.Text = "Bullets: "..bullets.Value
--resets mouse icon
mouse.Icon = "http://www.roblox.com/asset?id=90980978"
--fires server event that runs equipanimation
equipAnimation:FireServer(tool.shoot)
--sets debounce variable back to false
reloading = false
end
-- When the tool is equipped, the following event will run
tool.Equipped:Connect(function(mouse)
gungui:Clone().Parent = player.PlayerGui -- We are cloning the Gun GUI into the player's PlayerGUI
findBodyType() -- Calling the function above to check the body type.
equipAnimation:FireServer(tool.shoot) -- Calling the equip animation remoteevent so that the server can play the animation
mouse.Icon = "http://www.roblox.com/asset?id=90980978"
mouse.Button1Down:Connect(function()
if bullets.Value <=0 or reloading == true then
-- Don't do anything
else
--find which directino head is looking as CFrame..note: no period. between "Workspace and [player.Name]..
local head = game.Workspace[player.Name].Head.CFrame.lookVector
--finds head position cframe, then finds mouse.hit position, and finds the look vector of the mouse with this info as cframe
local mouse = CFrame.new(game.Workspace[player.Name].Head.Position,mouse.Hit.p).lookVector
--difference was initiated to "nil" at start of script
--uses above two lines, and finds difference between head and mouse,
--allowing you to see if you are trying to fire behind yourself, less than 1.33 is OK
difference = (head-mouse)
--raycast script below - create a ray. start point:(tool.handle.cframe.p) endpoint:(mouse hit position minus tool handle position) times number of studs
local ray = Ray.new(tool.Handle.CFrame.p,(player:GetMouse().Hit.p - tool.Handle.CFrame.p).unit*300)
--findpartonray script below
local part,position = game.Workspace:FindPartOnRay(ray,player.Character,false,true)
--plays gunfire sound
sound:Play()
--uses info above to check if character is shooting behind himself, and only shoots if sideways or front shooting
--allows character to shoot if 'difference' is less than 1.33
--magnitude proprty is the difference between two points
if difference.magnitude < 1.33 then
--this calls remoteevent 'shootevent' from replicated storage and passes arguments 'tool' 'position' and 'part'
shootevent:FireServer(tool,position,part)
--removes a bullet from inventory ..'bullets' is a variable referencing a global number value
--hence the property change (52m50s into video at this point)
bullets.Value = bullets.Value - 1
end
end
end)
--creates reload button for mobile users that do not have a keyboard
--arguments:(buttons name, function called, do we want a button to show on screen, what will button be?)
local reloadMobileButton = contextActionService:BindAction("ReloadBtn",reload,true,"r")
--sets position of button for mobile users
contextActionService:SetPosition("ReloadBtn",UDim2.new(0.72,-25,0.20,-25))
--sets image of reload button
contextActionService:SetImage("ReloadBtn","http://www.roblox.com/asset/?id=10952419")
end)
--this function called when tool unequipped
tool.Unequipped:Connect(function()
--get rid of gun mouse icon, and replace with standard mouse icon
mouse.Icon = ""
--fires server event to run unequip animation, passes in parameter of the animation tool.shoot because that
--animation was started when the gun was equipped, and it will be stopped when the gun is unequipped, so we have
--to pass it through to the server as well as an argument
unequipanimation:FireServer(tool.shoot)
--destroy the gunGUI since gun is unequipped (wouldn't it be better to reomve it?
player.PlayerGui.GunGUI:Destroy()
--gets rid of reload button
contextActionService:UnbindAction("ReloadBtn")
end)
--this is a client event awaiting firing by the main script on the server
headshot.OnClientEvent:Connect(function()
--get player and players gunGUI for the headshot GUI, and then tween the headshot label from its first position, the second position. the last 3
--arguments control the tween effect
player.PlayerGui.GunGUI.Headshot:TweenPosition(UDim2.new(0.5,-100,0.5,-25), "Out","Quint",0.3)
--keeps it on screen for 1.5sec
wait(1.5)
--tweens it offscreen again to right
player.PlayerGui.GunGUI.Headshot:TweenPosition(UDim2.new(-1,0,0.5,-25), "In","Quint",0.4)
wait(0.5)
--resets to original position offscreen at left
player.PlayerGui.GunGUI.Headshot.Position = UDim2.new(1.5,0,0.5,-25)
end)
--
main script can be posted too if needed
All help appreciated Thanks

5 comments
Here's the main script:
Don't use alvins tutorials, there garbage and are literally copied from other users.
Don't go around posting "alvinblock script no work help xd lol?", go create your own scripts.
imagine moderating year old question
Fragmentation123 - Your response was useless. To create your own scripts, you gotta learn to script. To learn to script, you have to use the resources available. AlvinBlox is just one resource. Don't be so useless in your responses. You wasted everyone's time with that.