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

why does Localplayer dosen't work?

Iam new to lua scripting and i want to make script which makes the head transparency to 0.5 who ever touches but this dosent work please HELP!.

Error :- 21:04:53.288 - Place1 was auto-saved to C:/Users/prudhvi/Documents/ROBLOX/AutoSaves/Place_AutoSave_1.rbxl 21:04:53.949 - Workspace.Part.Script:2: attempt to index global 'player' (a nil value) 21:04:53.949 - Stack Begin 21:04:53.950 - Script 'Workspace.Part.Script', Line 2 21:04:53.950 - Stack End

code :- ``player = game.Players.LocalPlayer char = player.Character head = char:FindFirstChild("Head") remove = script.Parent

remove.Touched:connect(function() head.Transparency = 0.5 end)``

1 comment

0

Put your code in a code block.

1 answer

✓ Accepted answer

LocalPlayer won't work since the localscript is not inside the player

U should use GetPlayerFromCharacter() to find the player

Like this:

remove.Touched:connect(function(hit) --I'm just guessing that remove is the brick

local player = game.Players:GetPlayerFromCharacter(hit.Parent) --Finds the player
local char = player.Character -- Finds the char

char.Head.Transparency = 0.5 --Sets head's transparency to 0.5

end)

I hope this helped ;)

1 comment

0

thanks man!

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