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?
01 | --Normal variables |
02 | local Player = game.Players.LocalPlayer |
03 | local char = Player.Character |
04 | local Mouse = Player:GetMouse() |
05 | local debounce = false |
06 | --Animation setup |
07 | local A = Instance.new( "Animation" ) |
08 | A.AnimationId = "http://www.roblox.com/Asset?ID=211592172" |
09 | local track = char.Humanoid:LoadAnimation(A) |
10 |
11 | function firewall(key) |
12 | if key = = "r" and not debounce and script.Parent.Equipped = = true then |
13 | local CF = game.ReplicatedStorage.FireWall:Clone() |
14 | CF.Parent = workspace |
15 | CF.MainPart.Position = char.Torso.Position + Vector 3. new( 5 , 0 , 0 ) |
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)!
01 | --Normal variables |
02 | local Player = game.Players.LocalPlayer |
03 | local Character = Player.Character or Player.CharacterAdded:wait() |
04 | local Humanoid = Character:WaitForChild( "Humanoid" ) |
05 | local Mouse = Player:GetMouse() |
06 | local debounce = false |
07 | --Animation setup |
08 | local Anim = Instance.new( "Animation" ) |
09 | Anim.AnimationId = "http://www.roblox.com/asset/?id=211592172" |
10 | local AnimTrack = Humanoid:LoadAnimation(Anim) |
11 |
12 | function firewall(key) |
13 | if key:lower() = = "r" and not debounce and script.Parent.Equipped then |
14 | debounce = true |
15 | local CF = game.ReplicatedStorage.FireWall:Clone() |
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.
01 | -- The UserInputService Version |
02 | --Normal variables |
03 | local Player = game.Players.LocalPlayer |
04 | local Character = Player.Character or Player.CharacterAdded:wait() |
05 | local Humanoid = Character:WaitForChild( "Humanoid" ) |
06 | local Mouse = Player:GetMouse() |
07 | local debounce = false |
08 | --Animation setup |
09 | local Anim = Instance.new( "Animation" ) |
10 | Anim.AnimationId = "http://www.roblox.com/asset/?id=211592172" |
11 | local AnimTrack = Humanoid:LoadAnimation(Anim) |
12 |
13 | UIS = game:GetService( "UserInputService" ) |
14 |
15 | function firewall(InputObject) |