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

I need help with identifying a player?

so I want it so that when R is clicked a weapon automaticlly equips on you (in this case a sword) but for some reason it doesnt work.

local BladeDash = game.StarterGui.Red.RedPower1.REDpower1
local player = game.Players.LocalPlayer
local character = player.Character




function onKeyPress(actionName, userInputState, inputObject)
	if userInputState == Enum.UserInputState.Begin then
		if BladeDash.Value == true then
			print ("hi")
			Workspace.player.Humanoid:EquipTool(Workspace.Tool)

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

so my issue is that roblox says "player is not part of workspace" how do I fix this?

1 answer

✓ Accepted answer

The player you referenced doesn't refer to your character, it instead refers to the player instance in game.Players. Simply just use player.Character instead of workspace.player.

EDIT: just realized you had a variable for character already, just use character instead :P

5 comments

0

Thanks so much !

0

wait but one more thing how would I be able to have the weapon be cloned before giving it to the player? so like when I click R a cloned weapon appears in the players hand. That way people could summon it again after they die

0

do "local toolclone = workspace.Tool:Clone()" followed by "character.Humanoid:EquipTool(a)"

0

Sorry I meant "character.Humanoid:EquipTool(toolclone)" make sure you remove the quotations lol

0

Thx so much guys I appreciate it

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