I made a script that is supposed to make the needle in the model show if the Players needle's liquid is Crimson. And print "You don't have any liquid in your needle" if your needle's liquid is Fossil. But the script isn't working there are no output errors but the script is a Normal script not Local or Module. The place I want it in is correct.
function OnClicked(player) local Plr = game.Players.LocalPlayer if Plr.Backpack.Collector.MovingParts.Change.Color == "Crimson" then print(player.Name.." clicked on blood extract.") local needle = script.Parent:WaitForChild("Needle") needle.Change.Transparency = 0 needle.NeedleGlass.Transparency = 0.3 elseif Plr.Backpack.Collector.MovingParts.Change.Color == "Fossil" then print("Player has no blood needle") end end script.Parent.ClickDetector.MouseClick:connect(OnClicked)
I was wondering how to fix this.
You cannot get the LocalPlayer from a Server Script. The LocalPlayer can only be called by a Local Script.
Also, if you have 'player' as a parameter, you won't probably need LocalPlayer since you can get the player that clicked the ClickDetector from that parameter.
function OnClicked(player) --[[ you have player as the parameter, this will automatically return the player that clicked on the ClickDetector.]] local Plr = game.Players.LocalPlayer --[[ can't get LocalPlayer from a Server Script (Normal Script). ]] if Plr.Backpack.Collector.MovingParts.Change.Color == "Crimson" then print(player.Name.." clicked on blood extract.") local needle = script.Parent:WaitForChild("Needle") needle.Change.Transparency = 0 needle.NeedleGlass.Transparency = 0.3 elseif Plr.Backpack.Collector.MovingParts.Change.Color == "Fossil" then print("Player has no blood needle") end end script.Parent.ClickDetector.MouseClick:connect(OnClicked)
If you want to run this in a Server Script, then the script would probably go like this:
function OnClicked(player) if player.Backpack.Collector.MovingParts.Change.Color == "Crimson" then print(player.Name.." clicked on blood extract.") local needle = script.Parent:WaitForChild("Needle") needle.Change.Transparency = 0 needle.NeedleGlass.Transparency = 0.3 elseif player.Backpack.Collector.MovingParts.Change.Color == "Fossil" then print("Player has no blood needle") --[[ if you want this to print the player that clicked on the ClickDetector, it'll be print(player.Name.." has no blood needle")]] end end script.Parent.ClickDetector.MouseClick:connect(OnClicked)
Remember, you cannot get the LocalPlayer from a Server Script (Normal, not Local Script).