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

why does Localplayer dosen't work?

Asked by 8 years ago
Edited 8 years ago

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)``

0
Put your code in a code block. Netflixy 126 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago
Edited 8 years ago

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 ;)

0
thanks man! theepicspider1 15 — 8y
Ad

Answer this question