So i’m trying to remake the chainsaw glory kill from Doom Eternal, and i’m trying to get to a point where I can walk up to a dummy (that has the script in it) and press F to fire an event.
So the code below is from a post made in may, which should work, but doesn’t.
local UIS = game:GetService('UserInputService')
local plr = game.Players.LocalPlayer
UIS.InputBegan:Connect(function(input,gpe)
if input.KeyCode == Enum.KeyCode.X and not gpe then -- X is just an example change it to whatever you want.
if (plr.Character.HumanoidRootPart.Position - yourPart.Position).magnitude <= 10 then -- 10 is the distance in studs
-- you can fire your event here to handle it.
end
end
end)
That code requires a LocalScript and that it be located in some client-specific location. If the dummy model is located in workspace (and not a child of the camera) then it won’t do anything.
From what I’m seeing, this code was likely given to you by someone else. It needs to go in a LocalScript, then probably into StarterCharacterScripts, and you need to define the variable “yourPart”