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

I need help with identifying a player?

Asked by 6 years ago

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

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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

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

0
Thanks so much ! turbomegapower12345 48 — 6y
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 turbomegapower12345 48 — 6y
0
do "local toolclone = workspace.Tool:Clone()" followed by "character.Humanoid:EquipTool(a)" ultrasonicboomer 85 — 6y
0
Sorry I meant "character.Humanoid:EquipTool(toolclone)" make sure you remove the quotations lol ultrasonicboomer 85 — 6y
0
Thx so much guys I appreciate it turbomegapower12345 48 — 6y
Ad

Answer this question