local tool = script.Parent
local equipado = false
local maxammo = 50
local MouseD = false
tool.Equipped:connect(function(equipar)
equipado = true
char = tool.Parent
player = game.Players:GetPlayerFromCharacter(char)
equipar.Icon = "http://www.roblox.com/asset/?id=79658449"
gui = tool.GUI:Clone()
gui.Parent = player.PlayerGui
end)
function reload()
if tool.ammo.Value ~= 50 and tool.ammo.Value <50 then
wait(2)
tool.ReloadSound:play()
tool.ammo.Value = 50
end
end
equipar.KeyDown:connect(function(key)
key = key:lower()
if key == "r" then
reload()
end
end)
-- Disparando
equipar.Button1Up:connect(function()
MouseD = false
end)
equipar.Button1Down:connect(function()
MouseD = true
if script.Parent.ammo >0 then
tool.FireSound:play()
tool.ammo.Value = tool.ammo.Value - 1
tool.Flash.PointLight.Brightness = 5
tool.Flash.Transparency = 0
bala = Instance.new("Part")
bala.Parent = Workspace
bala.BrickColor = BrickColor.new("Cool yellow")
bala.Size = Vector3.new(1,1,1)
bala.Name = B
remover = script.Parent.remover:Clone()
remover.Parent = bala
balaM = Instance.new("SpecialMesh")
balaM.MeshType = "Sphere"
balaM.Parent = bala
balaM.Scale = Vector3.new(0.2,0.2,0.2)
wait(0.05)
tool.Flash.PointLight.Brightness = 0
tool.Flash.Transparency = 1
end
end)
Why my game crash when i try to equip or pick up this tool?
1 answer
Spanish scripter huh? Glad to see i'm not the only spanish scripter here.
--[[Line 59]] bala.Name = B
The script doesn't seem to show any value called "B" If these weren't your intentions, Use
bala.Name="B"
In the rest, I don't see anything wrong, except for the line 19, We don't know if it has a loop or anything in the Cloned Gui, but your script can be optimized.
But could really that line make your game crash? Are you sure you have any "While true do" loops in your game or tool?
Weld scripts have a small chance of crashing your game too.
Honestly having a while "true" do in the while loop is completely pointless, waste of code, many people do that.
A better way is using:
while wait() do
print("Sup")
end
--[[If you're using the loop to update certain properties or values of an object, for performance reasons, it's suggested to use]]
while wait(1.5) do --Could be longer or shorter, you decide.
--ValueUpdate
end
2 comments
Yes, its seems like in the gui script say "while true do" without any wait and i know that error but i literally didnt notice about that when i was coding it!. If you're a spanish scripter can u pls add me to roblox?, i mean i dont know if you talk spanish or you're spanish, but youre my salvation dude im new on this and youre professional!!. I literally thanks you if you can talk spanish with me
Yeah, I'm between of Colombia and Venezuela, so of course I speak spanish, I speak both languages. If you have any questions, feel free to PM me and i'll do my best.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Are you sure it's this tool? I don't see any issues and am guessing the problem is in the GUI (if it contains scripts) that you clone en line 17