Taser Script Help

I’m making a Taser Tool for my roleplay game, and I didn’t know hot to make one, So I used a quick YouTube tutorial to help me. With this script in order for them to get tased the tool has to touch them, how do I make it so that if you click on the player, they sit instead of me having to run up to the player and touch them with the tool?

Script:

local Tool = script.Parent
local Handle = Tool.Handle
local Sound = Tool.TASER_DEPLOY

local Debounce = false
if Debounce == false then
	Debounce = true
	Tool.Activated:Connect(function()
		Sound:Play()
		wait(5)
		Sound:Stop()
		Handle.Touched:Connect(function(Hit)
			local Humanoid = Hit.Parent:FindFirstChildWhichIsA("Humanoid")
			if Humanoid then
				Humanoid.Sit = true
				wait(5)
				Humanoid.Sit = false
				wait(5)
				Debounce = false
			end
		end)
	end)
end

You gotta make Tool.Activated in local script + remote event that gives info to the server that makes them sit.
In local script:

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
script.Parent.Activated:Connect(function()
    local plr2 = game.Players:GetPlayerFromCharacter(Mouse.Target.Parent)
    if plr2 then
        remote:FireServer(Mouse.Target.Parent) -- Sends the part that player tried to use tazer on
    end
end)

Then on server check if players are not too far away

remote.OnServerEvent:Connect(function(PlayerWithTaser, TargettedCharacter)
    local Player1Magnitude = PlayerWithTaser.Character.HumanoidrootPart.Position.Magnitude
    local Player2Magnitude = TargettedCharacter.HumanoidrootPart.Position.Magnitude
    if Player1Magnitude - Player2Magnitude < MaxTaserReach then
-- make player sit
    end
end)
1 Like

Hello,
I think you can read article which roblox created about Hit Detection (basically guns). They cover topics such how to detect another player,create beam etc.

Here’s it: Hit Detection with Lasers | Documentation - Roblox Creator Hub

Of course you can modificate this script and instead of taking damage you can create stun (for example).

I hope it will help you.

1 Like

How would I make all the scripts together?

Tool activated → Raycast, detect the hit, make em sit

Put the server script, local script and remote event all into the taser tool