local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local UIS = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Create the GrabAnimation instance
local grabAnimation = Instance.new("Animation")
grabAnimation.AnimationId = "rbxassetid://77325448756458" -- Use your actual animation ID
grabAnimation.Name = "GrabAnimation" -- Name it for reference
local grabbedAnimation = Instance.new("Animation")
grabbedAnimation.AnimationId = "rbxassetid://99980972320345" -- Use your actual animation ID
grabbedAnimation.Name = "GrabbedAnimation" -- Name it for reference
local slitAnimation = Instance.new("Animation")
slitAnimation.AnimationId = "rbxassetid://82839889243848" -- Use your actual animation ID
slitAnimation.Name = "SlitAnimation" -- Name it for reference
local clickSoundEvent = ReplicatedStorage:WaitForChild("ClickSoundEvent")
local isgrabbing = false
local grabbed = false
local weld
-- Wait for tool to be equipped
player:GetAttributeChangedSignal("ToolEquipped"):Connect(function()
if player:GetAttribute("ToolEquipped") then
local humanoid = character:WaitForChild("Humanoid")
-- Load the animations
local grabtrack = humanoid:LoadAnimation(grabAnimation)
local grabbedtrack = humanoid:LoadAnimation(grabbedAnimation)
local slittrack = humanoid:LoadAnimation(slitAnimation)
local weldpart = character:FindFirstChild("weldpart")
-- Input detection
if grabbed == false then
local function GetVictim(weldpart, character)
local Hitbox = workspace:GetPartsInPart(weldpart)
local HRP = nil
for _, X in pairs (Hitbox) do
local Parent = X.Parent
local IsModel = Parent:IsA("Model")
local Hum = Parent:FindFirstChildOfClass("Humanoid")
if IsModel and Hum and Parent.Name ~= player.Name then
print("Found victim:", Parent)
HRP = Hum.RootPart
break
else
print("not yourself!")
end
end
return HRP
end
local hasGrabbed = false -- Tracks if a target is grabbed
UIS.InputBegan:Connect(function(input)
if input.UserInputType ~= Enum.UserInputType.MouseButton1 then return end
local weldpart = player.Character:FindFirstChild("weldpart")
local victimroot = GetVictim(weldpart)
if not hasGrabbed then
-- Attempt to grab
clickSoundEvent:FireServer()
grabtrack:Play()
if victimroot then
-- Perform grabbing actions
grabbedtrack:Play()
victimroot.CFrame = weldpart.CFrame
weld = Instance.new("WeldConstraint")
weld.Parent = weldpart
weld.Part0 = weldpart
weld.Part1 = victimroot
hasGrabbed = true -- Update state to indicate target is grabbed
print("Target grabbed")
end
else
-- Perform slit action
slittrack:Play()
grabbedtrack:Stop()
task.wait(1)
local victim = victimroot.Parent
print(victim, "Killed")
local health = victim.Humanoid.Health
health = health - 100
weld:Destroy()
hasGrabbed = false -- Reset state to allow grabbing again on next click
print("Target released with slit")
end
end)
end
end
end)
This is the local script. Everything here should happen on the server, but since it involves clicking, I wanted it to be in a local script.
One problem are the variables. How do I get these variables inside the remote event function? I have a welding function which is connected to a remote event.
How do I get the weld- and weldpart variable inside the remote event function?