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

I need it directed at the person who selected it. Not a general username, how?

so i have character selection done, because i have worked on something like that before, though I'm not quite sure how i can make it so it applies to anybody who selects wolverine, i want it so it applies to the user that selects the wolverine character instead of it being directed towards my username, and that it toggles with Q instead of needing 2 keybinds.. Where is says game.Workpace.TheForgxttenDev i want it so it's applied to whomever selects that character. Does anybody know how I could do this. This is my current script.

game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.Z then game.Workspace.TheForgxttenDev.LeftClaw.Transparency = 0 game.Workspace.TheForgxttenDev.RightClaw.Transparency = 0

end 

end)

game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.X then game.Workspace.TheForgxttenDev.LeftClaw.Transparency = 1 game.Workspace.TheForgxttenDev.RightClaw.Transparency = 1 end end)

1 comment

0

Please do put the whole code in Lua Block Code, it will be easier to read the code in that.

1 answer

Put your code in Lua block code so it will be easier to read

In your code you type in your name, so obviously it will choose you.

You need place the code in a LocalScript script and place it inside StarterPack or StarterCharacterScripts.

local player = game.Players.LocalPlayer --We find the local player. meaning we find the player the way you want to do it.
local character = player.CharacterAdded:Wait() --We wait for the character to load so it wont give us an error that the Character doesnt exist since scripts run faster than the game's loading speed
local LClaw = character:FindFirstChild("LeftClaw")
local RClaw = character:FindFirstChild("ReftClaw")

local uis = game:GetService("UserInputService")

rightClawOut = false --Claws are not out so we will check when they will be out so we can get them back in again if the claws are out.
leftClawOut = false

uis.InputBegan:Connect(function(key, gameProcessedEvent)
	if key.KeyCode == Enum.KeyCode.E and not gameProcessedEvent then
		if rightClawOut == false then
			RClaw.Transparency = 0
			rightClawOut = true
		end
	end
	if key.KeyCode == Enum.KeyCode.Q and not gameProcessedEvent then
		if lightClawOut == false then
			LClaw.Transparency = 0
			lightClawOut = true
		end
	end
end

uis.InputEnded:Connect(function() --I assume you know what to do here, basically the opposite, now check when they click E or Q and if the claws bool values are true (claws are out) just make them transparent again

NOTE: This will work, but only locally. You will have to use RemoteEvents to be able to fire an event to a server script and be able to change the transparency of the claws Server side too so the rest of the server will see the claws. If you do it locally only you will be able to see your claws go transparent while the rest of the players around you wont.

Check this out: https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

I learned RemoteEvent easily by this video: (https://www.youtube.com/watch?v=4Dc_bri9mjs

It may look complex but its not, once you do it couple of times (like I did) - its really easy.

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