Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

User input script refuses to work?

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.

9 comments

1

line 13 just remove the .Parent = game.Workspace, cause you already have "=" in your variable.

0

just place it somewhere else, like below the Variable CF.

0

I did, thank you.

0

Worked?

0

I can't test it at school roblox is blocked.

0

xD, kk

0

Made a tiny edit

0

did it work?

0

Nope. I think I'm going to put this project to rest. It obviously doesn't want to work.

1 answer

  • 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)

This discussion is preserved as it was. New answers, comments, and votes are closed.