Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I code a tool for everyone to see?

Asked by 7 years ago
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?

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. NecoBoss 194 — 7y
0
L0l yes it is FE thehybrid576 294 — 7y

1 answer

Log in to vote
0
Answered by
cabbler 1942 Moderation Voter
7 years ago

Simply start the tool.Activated function in a localscript, then send mouse information for the server to replicate. No you can't send the whole mouse. Use a remote event. The wiki may explain better than us. http://wiki.roblox.com/index.php?title=Building_Games_with_Filtering_Enabled

Ad

Answer this question