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

idk whats wrong with my script, im trynna change some physical propreties can any1 help?


local userInputService = game:GetService("UserInputService")
local lightningService = game:GetService("Lighting")

local animation = lightningService:WaitForChild("Animation")
local idle = animation:WaitForChild("Idle")


local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")

local animationTrack = humanoid:LoadAnimation(idle)
local animationPlaying = false

userInputService.InputBegan:Connect(function(Input, Chat)
    if Input.KeyCode == Enum.KeyCode.F and not Chat and humanoid.Health >= 0 then
        if not animationPlaying then
player["LeftHand"].Reflectance = 0.5 wait(0.1) player["LeftHand"].Reflectance = 1
	player["RightHand"].Reflectance = 0.5 wait(0.1) player["RightHand"].Reflectance = 1
            animationTrack:Play()
            animationPlaying = true
        elseif animationPlaying then
player["LeftHand"].Reflectance = 0.5 wait(0.1) player["LeftHand"].Reflectance = 0
	player["RightHand"].Reflectance = 0.5 wait(0.1) player["RightHand"].Reflectance = 0
            animationTrack:Stop()
            animationPlaying = false
        end
    end
end)

when i try to change the left and right hand propreties the script stops working

1 answer

✓ Accepted answer

Parent

Please don't use the Lightning service. It has been deprecated for a long time now. Instead make use of the proper Storage services ROBLOX has to offer. ReplicatedStorage is a great place to store objects that want accessible by both the server and client.

ServerStorage is a great place to store objects you only want accessible by the server. Things you want to hide from the client can be stored inside of ServerStorage.

Please read up on the ways to store objects on the wiki if you want to know more about them.

Problem

You're trying to find the LeftHand and RightHand inside of the Player object, and not the Character object.

This could easily be fixed by doing

character:FindFirstChild("LeftHand").Reflectance = 0.5 

instead of

player:FindFirstChild("LeftHand").Reflectance = 0.5 

It's also good practice to use FindFirstChild when trying to find objects.

Implementation

userInputService.InputBegan:Connect(function(Input, Chat)
    if Input.KeyCode == Enum.KeyCode.F and not Chat and humanoid.Health >= 0 then
        if not animationPlaying then
			character:FindFirstChild("LeftHand").Reflectance = 0.5 
			wait(0.1) 
			character:FindFirstChild("LeftHand").Reflectance = 1
			
    		character:FindFirstChild("RightHand").Reflectance = 0.5 
			wait(0.1) 
			character:FindFirstChild("RightHand").Reflectance = 1
 
            animationTrack:Play()
            animationPlaying = true
		elseif animationPlaying then
			character:FindFirstChild("LeftHand").Reflectance = 0.5 
			wait(0.1) 
			character:FindFirstChild("LeftHand").Reflectance = 0
			
    		character:FindFirstChild("RightHand").Reflectance = 0.5 
			wait(0.1) 
			character:FindFirstChild("RightHand").Reflectance = 0

            animationTrack:Stop()
            animationPlaying = false
        end
    end
end)

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