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

How to do you get the player's character from starter Gui?

I'm making a flashlight Gui when you click the gui it turns on and off. I got the light working in starterplayerscripts, but can get the same effect from having a local script in Starterguis .

Here is my local script in the Gui in Starterguis


local player = game.Players.LocalPlayer
local Character = player.Character
local Light = player.Character.HumanoidRootPart.PointLight
Light.Enabled = false


script.Parent.MouseButton1Click:Connect(function()
	if player.Character then
		Light.Enabled = not Light.Enabled
		
	end



end)

Here is the working local script in starterplayerscripts

local Character = script.Parent
local Light = Instance.new("PointLight", Character:WaitForChild("HumanoidRootPart"))
Light.Enabled = false
Light.Color = Color3.fromRGB(0, 255, 0)
Light.Brightness = 2
Light.Range = 10
Light.Shadows = true
local UserInputService = game:GetService("UserInputService")
local function onInputBegan(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.F then
			Light.Enabled = not Light.Enabled
		end
	end
end
UserInputService.InputBegan:Connect(onInputBegan)

2 answers

Bruh I literally just answered someone else who did the same thing. You're supposed to use false.

Light.Enabled = false

2 comments

1

LOLLLLLLL no one knows that true and false exists

0

Do you mean replace the ~~~~~~~~~~~~~~~~~ Light.Enabled = not Light.Enabled ~~~~~~~~~~~~~~~~~ with ~~~~~~~~~~~~~~~~~ Light.Enabled = false ~~~~~~~~~~~~~~~~~ Because that didn't work,? the problem seems to be that, the scrip don't know where the light is.

I got it working replaced the gui local script with

 

script.Parent.MouseButton1Click:Connect(function()
	local player = game.Players.LocalPlayer
	local human = player.Character:FindFirstChild("HumanoidRootPart")
	local Light = human:FindFirstChild("PointLight")
	
	Light.Enabled = not Light.Enabled 
	
end)

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