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

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

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.

1 comment

0

at line 13 you should change into Button1Click or just ButtonClick try both of them

1 answer

✓ Accepted answer

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.

2 comments

0

Oops, make sure if qp ~= false then is inside tool.Activated.

0

Thanks! it helped a lot

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