Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I code a tool for everyone to see?

local tool = script.Parent
local handle = script.Parent.Handle
local sounds = {
	a = handle.ShootSound,
	b = handle.ExplodeSound
}
local canFire = true

local function explodeFunc(part)
	part.Anchored = true
	part.Transparency = 1
	part.ExplodeSound:Play()
end
tool.Activated:connect(function()
	if canFire == true then
		local player = game.Players[tool.Parent.Name]
		local mouse = player:GetMouse()
		canFire = false
		sounds.a:Play()
		local firePart = Instance.new("Part", game.Workspace)
		firePart.Name = "FirePart"
		firePart.Shape = "Ball"
		firePart.Material = "SmoothPlastic"
		firePart.Anchored = false firePart.CanCollide = false
		firePart.Size = Vector3.new(.2, .2, .2)
		firePart.CFrame = handle.CFrame
		firePart.CFrame = CFrame.new(handle.Position, mouse.Hit.p)
		game:GetService("Debris"):AddItem(firePart, 6)
		local clone1 = sounds.b:Clone()
		clone1.Parent = firePart
		local bv = Instance.new("BodyVelocity", firePart)
		bv.velocity = firePart.CFrame.lookVector * 90
		bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
		firePart.Touched:connect(function(hit)
			if hit ~= handle and hit.Name ~= "FirePart" then
				local humCheck = hit.Parent:FindFirstChild("Humanoid")
				if humCheck and humCheck ~= nil then
					if humCheck ~= tool.Parent.Humanoid then
						explodeFunc(firePart)
					end 
				elseif hit.Parent ~= humCheck then
					explodeFunc(firePart)
				end
			end
		end)
		wait(3)
		canFire = true
	end
end)

On the line where I get the mouse 'player:GetMouse()', it errors, I know because it is a server-script inside of the tool. How else can I get the mouse in a server-script so all player's can see what the tool does?

2 comments

0

Do you have Filtering Enabled? Either way, you should go to YouTube and watch roblox university murder tutorial. It will show you how to build a gun.

0

L0l yes it is FE

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.