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

User input script refuses to work?

Asked by
yoshiegg6 176
9 years ago

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.

1
line 13 just remove the .Parent = game.Workspace, cause you already have "=" in your variable. woodengop 1134 — 9y
0
just place it somewhere else, like below the Variable CF. woodengop 1134 — 9y
0
I did, thank you. yoshiegg6 176 — 9y
0
Worked? woodengop 1134 — 9y
View all comments (5 more)
0
I can't test it at school roblox is blocked. yoshiegg6 176 — 9y
0
xD, kk woodengop 1134 — 9y
0
Made a tiny edit yoshiegg6 176 — 9y
0
did it work? woodengop 1134 — 9y
0
Nope. I think I'm going to put this project to rest. It obviously doesn't want to work. yoshiegg6 176 — 9y

1 answer

Log in to vote
0
Answered by
Redbullusa 1580 Moderation Voter
9 years ago
  • 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)
Ad

Answer this question