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

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

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago

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

Light.Enabled = false
1
LOLLLLLLL no one knows that true and false exists Cyrus_O4 45 — 3y
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. Boss246813579 -6 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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)

Answer this question