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

Needle normal script not runningto make a needle show if you have a tool part have a certain color?

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.

4 comments

0

I'm not asking for a whole remake of the script.

0

If it's a normal script, I don't think you can use LocalPlayer. Where is the script located exactly???

0

Try using a local script instead

0

Ok.

2 answers

✓ Accepted answer

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

10 comments

0

Or, you could just run this in a LocalScript like the other people are saying.

0

^ OP will run into problem of the script's effects not being replicated to server, though

1

also the fact that OP is using .Color to check for Brick Colors

0

Well then he's gonna have to learn how to use Remotes, if he's going to run this in a LocalScript.

0

Crap, you're right, the .Color should be .BrickColor, I should've catched that @CPF2

1

I would also recommend for him to use tabs

0

@oilsauce, it's fine, I didn't even consider that this was/should be a server script, thought it was just a local one.

0

Right I forgot about BrickColour.

0

Welp nearly every video I tried to learn Remotes didn't have anything close to this.

0

Nvm

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