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

How do I make this script in the explosion tool work?

Asked by 3 years ago

I have 2 scripts in a tool local and normal

Main(normal):

local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local Storage = game:GetService("ReplicatedStorage")
local remoteEvent = Storage:WaitForChild("Explosion")
local at = 2

local function explo(player)
    tool.Activated:Connect(function()
        local mouse = player:GetMouse()
        local expo = Instance.new("Explosion", workspace)
        expo.Position = mouse.Hit.Position
        wait(at)
        expo:Destroy()
    end)
end


remoteEvent.onServerEvent:Connect(explo)

local:

local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()
local codwn = false
local at = 1
local qp = false


tool.Equipped:Connect(function()
    qp = true
    if qp ~= false then
        mouse.Button1Down:Connect(function()
            if codwn ~= true then
                codwn = true
                tool:Activate()
                wait(at)
                tool:Deactivate()
                codwn = false
            end
        end)
    end
end)

tool.Deactivated:Connect(function()
    qp = false
end)

I tried to make it work with remote event called Explosion but didn't seem to work.

0
at line 13 you should change into Button1Click or just ButtonClick try both of them SiperStrengh35974 5 — 3y

1 answer

Log in to vote
0
Answered by
notfenv 171
3 years ago

In your Tool.Equipped section, move

if qp ~= false then
            mouse.Button1Down:Connect(function()
                if codwn ~= true then
                    codwn = true
                    tool:Activate()
                    wait(at)
                    tool:Deactivate()
                    codwn = false
                end
            end)
        end

outside of the connection.

For the server, the function variables should be player, hitp. Then on the client, instead of Tool:Activate() fire the remote with the arguments mouse.Hit.Position. (game.ReplicatedStorage.Explosion:FireServer(mouse.Hit.Position)

Make sure to remove Tool:Deactivate()!

Your server should look like this:

local function explo(player, hitp)
    local expo = Instance.new("Explosion", workspace)
    expo.Position = hitp
    wait(at)
    expo:Destroy()
end

and your client should look like this:

if qp ~= false then
            tool.Activated:Connect(function()
                if codwn ~= true then
                    codwn = true
                    game.ReplicatedStorage.Explosion:FireServer(mouse.Hit.Position)
                    wait(at)
                    codwn = false
                end
            end)
        end

Sorry if this is confusing for you, it's 4 AM.

0
Oops, make sure if qp ~= false then is inside tool.Activated. notfenv 171 — 3y
0
Thanks! it helped a lot RedSoloYT 10 — 3y
Ad

Answer this question