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

Is there a way to equip a tool give a tool and equip when press the number 1 in the keyboard?

Is there a way to equip a tool give a tool and equip when press the number 1 in the keyboard? i dont want try this and dont work, and i dont know too much about KeyDown function, so i dont waste my time trying, is there a way to do this?

now i know that i need use this script as base:

function onKeyPress(actionName, userInputState, inputObject)
	if userInputState == Enum.UserInputState.Begin then
		print("R was pressed")
	end
end
 
game.ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.R)

but where i put this? in staterplayerscript? in a personalscript?

3 comments

0

That's confusing. If possible, could you elaborate? Other than that, I can only help you with this: http://wiki.roblox.com/index.php?title=Keyboard_input

0

Please elaborate more on this question. Give some background information, and please post any code snippits you have.

0

reset, that was what i was looking for, thx ^^

1 answer

✓ Accepted answer

ok so instead of using lightning, I'll use replicatedstorage because it's more efficient.

This is a local script that should be in starterplayer under starterplayerscripts

This local script clones the tool if it once R is pressed but if there already is a tool that was cloned by this script then the script will reset for the next time that someone presses R.

I don't have enough information to do this once a player is not on a map or whatever because I don't know what the names of the instances are or what your game is about.

local replicatedstorage = game:GetService("ReplicatedStorage")

local tool = replicatedstorage:WaitForChild("bob") -- replace bob with tool name

local plr = game.Players.LocalPlayer

function onKeyPress(actionName, userInputState, inputObject)
    if userInputState == Enum.UserInputState.Begin then
	if plr:WaitForChild("Backpack"):FindFirstChild("bob") then -- if there already is a tool that was cloned then script will end
		return end 
	elseif not plr.Backpack:FindFirstChild("bob") then -- if a tool wasnt already cloned then it will clone it 
        local toolCloning = tool:Clone()
		toolCloning.Parent = plr.Backpack -- once r is pressed the tool will clone itself into the players backpack
    end
end

game:GetService("ContextActionService"):BindAction("keyPress", onKeyPress, false, Enum.KeyCode.R)

6 comments

0

look, i want when he press, the tool will be cloned from the lighting, to the player backpack, and dont when he spawn in the map

0

oh ok ill edit my answer

0

there I gave a new answer instead of lightning it uses ReplicatedStorage because that's much better than using lighting

0

ok, i will try

0

thxxxxx, it worked, thx for helping me ^^

0

no prob :)

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