Please, if anyone knows how to fix this please help. I've been debugging this for weeks.
This is in a local script in a tool and it doesn't work. It's supposed to clone a model from replicated storage to right in front of your character when you press r and it uses mouse key down. There is no output but it still doesn't work. Can anyone help me?
--Normal variables local Player = game.Players.LocalPlayer local char = Player.Character local Mouse = Player:GetMouse() local debounce = false --Animation setup local A = Instance.new("Animation") A.AnimationId = "http://www.roblox.com/Asset?ID=211592172" local track = char.Humanoid:LoadAnimation(A) function firewall(key) if key == "r" and not debounce and script.Parent.Equipped == true then local CF = game.ReplicatedStorage.FireWall:Clone() CF.Parent = workspace CF.MainPart.Position = char.Torso.Position + Vector3.new(5,0,0) CF.Rotation = char.Torso.Rotation --Edit: I capitalised the f in CF here track:Play() debounce = true wait(3) debounce = false end end Mouse.KeyDown:connect(firewall)
Please, if you can fix this I will upvote every single thing you've posted.
Edit: Followed europes advice, I'm going to test it.
Indent your code in a more professional manner. People will take you as an organized scripter!
Since you're using the .KeyDown event, lower the key, so your key wouldn't be read as a capital "R," else the function will not run.
Wait for the character (just in case if it is nil)!
--Normal variables local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:wait() local Humanoid = Character:WaitForChild("Humanoid") local Mouse = Player:GetMouse() local debounce = false --Animation setup local Anim = Instance.new("Animation") Anim.AnimationId = "http://www.roblox.com/asset/?id=211592172" local AnimTrack = Humanoid:LoadAnimation(Anim) function firewall(key) if key:lower() == "r" and not debounce and script.Parent.Equipped then debounce = true local CF = game.ReplicatedStorage.FireWall:Clone() CF.Parent = workspace --[[ Give CFrame a try! CF.MainPart.Position = char.Torso.Position + Vector3.new(5,0,0) CF.Rotation = Character.Torso.Rotation --]] CF:SetPrimaryPartCFrame(Character.Torso.CFrame * CFrame.new(0, 0, -5)) -- I believe it is the Z-axis is what you want. AnimTrack:Play() wait(3) debounce = false end end Mouse.KeyDown:connect(firewall)
I would like to introduce you to the UserInputService.. It's pretty cool. It is way more compatible with other devices than the deprecated .KeyDown event.
-- The UserInputService Version --Normal variables local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:wait() local Humanoid = Character:WaitForChild("Humanoid") local Mouse = Player:GetMouse() local debounce = false --Animation setup local Anim = Instance.new("Animation") Anim.AnimationId = "http://www.roblox.com/asset/?id=211592172" local AnimTrack = Humanoid:LoadAnimation(Anim) UIS = game:GetService("UserInputService") function firewall(InputObject) if InputObject.KeyCode == Enum.KeyCode.R and not debounce and script.Parent.Equipped then debounce = true local CF = game.ReplicatedStorage.FireWall:Clone() CF.Parent = workspace --[[ CF.MainPart.Position = char.Torso.Position + Vector3.new(5,0,0) CF.Rotation = Character.Torso.Rotation --]] CF:SetPrimaryPartCFrame(Character.Torso.CFrame * CFrame.new(0, 0, -5)) AnimTrack:Play() wait(3) debounce = false end end UIS.InputBegan:connect(firewall)