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

why isnt my Part.CanTouch = true/false script not working?

Asked by 2 years ago
Edited 2 years ago
local keyPressed = Enum.KeyCode.F
local animationId = "0000000000" 

local userInputService = game:GetService("UserInputService") 
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://"..animationId
local animationTrack = humanoid:LoadAnimation(animation)
local Attack = script.parent.AttackBox
local base = script.parent.HumanoidRootPart

userInputService.InputBegan:Connect(function(input,isTyping)
    if isTyping then return end
    if input.KeyCode == keyPressed then
        if not animationTrack.IsPlaying then
            animationTrack:Play()
            Attack.CanTouch = true
            base.Anchored = true
            wait(1.5)
            Attack.CanTouch = false
            base.Anchored = false
        end
    end
end)

everything in this script works as planned, except for CanTouch. the block is off touch in the model, and the local location is correct. how do i fix this? is there a line of text im missing or do i have something misspelled here? This is my first time using CanTouch, apologies if this is noob stuff

Answer this question