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

Why doesn't anything from if key == "c" then work?

player = game.Players.LocalPlayer
mouse = player:GetMouse()
shaUp = false
enabled = true
sha2 = false
sha1 = true


mouse.KeyDown:connect(function(key)
	if player.Character.Humanoid.Health >0 then
		if key == "x" and enabled == true and shaUp == false and sha1 == true then
	key = key:lower()
enabled = false
shaUp = true
sha1 = false
local y = game.ReplicatedStorage.Me:clone()
y.Parent = game.Workspace
y.Name = player.Name
y.Torso.CFrame = player.Character.Torso.CFrame*CFrame.new(0,0,5)
sha1 = true
shaUp = true
print("Work")
mouse.Button1Down:connect(function(m)
y.Humanoid.WalkToPoint = mouse.hit.p
end)
wait()
enabled = true
if key == "c" then
player.Character.Humanoid.Health = 0
end
end
	end
end)

You clone a shadow like figure from replicated storage. If you press c your supposed to die. Maybe I got confused with the true,false,etc?

5 comments

0

you should use UIS. not keydown

0

UIS?

0

User Input Service

0

I think I'll stick with KeyDown

0

Mouse.KeyDown is deprecated. This is a bad idea.

1 answer

✓ Accepted answer

I agree with John's comment that the UserInputService should be used instead of KeyDown and you can read all of the events and functions here. Also, you have your if statements inside of each other, which is hard to tell because of the spacing.

local IS = game:GetService("UserInputService")
local PLAYER = game.Players.LocalPlayer
local MOUSE = player:GetMouse()
local shaUp = false
local ENABLED = true
local sha1 = true
local sha2 = false

-- InputBegan fires when they player presses anything, button,mouse,controller
IS.InputBegan:connect(function(INPUT) -- INPUT is what they pressed
	if INPUT.UserInputType == Enum.UserInputType.Keyboard then -- this checks if it was a keyboard button pressed
		if INPUT.KeyCode == Enum.KeyCode.X and ENABLED == true and shaUp == false and sha1 == true  then 
--this checks the key pressed and all that all of those boolean values are either true or false
			ENABLED = false
			shaUp = true
			sha1 = false
			local y = game.ReplicatedStorage.Me:clone()
			y.Parent = game.Workspace
			y.Name = player.Name
			y.Torso.CFrame = player.Character.Torso.CFrame*CFrame.new(0,0,5)
			sha1 = true
			shaUp = true
			print("Work")
			MOUSE.Button1Down:connect(function(m)
				y.Humanoid.WalkToPoint = mouse.hit.p
			end) -- ends the mouse
			wait()
			enabled = true
		end -- this ends if X was pressed
		if INPUT.KeyCode == Enum.KeyCode.C then 
			PLAYER.Character.Humanoid.Health = 0
		end
	end
end)

Please remember to accept my answer if it is correct or helps you solve your problem. If anything errors or there is anything wrong please comment and/or message me before you start downvoting. ;)

1 comment

0

Thanks I'll start looking into UIS instead of eyDown

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