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

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

Asked by 5 years ago

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.

0
I'm not asking for a whole remake of the script. oshawat00 62 — 5y
0
If it's a normal script, I don't think you can use LocalPlayer. Where is the script located exactly??? ScrewDeath 153 — 5y
0
Try using a local script instead maup12345 20 — 5y
0
Ok. oshawat00 62 — 5y

2 answers

Log in to vote
0
Answered by
oilsauce 196
5 years ago

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

0
Or, you could just run this in a LocalScript like the other people are saying. oilsauce 196 — 5y
0
^ OP will run into problem of the script's effects not being replicated to server, though ScrewDeath 153 — 5y
1
also the fact that OP is using .Color to check for Brick Colors CPF2 406 — 5y
0
Well then he's gonna have to learn how to use Remotes, if he's going to run this in a LocalScript. oilsauce 196 — 5y
View all comments (6 more)
0
Crap, you're right, the .Color should be .BrickColor, I should've catched that @CPF2 oilsauce 196 — 5y
1
I would also recommend for him to use tabs maup12345 20 — 5y
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. CPF2 406 — 5y
0
Right I forgot about BrickColour. oshawat00 62 — 5y
0
Welp nearly every video I tried to learn Remotes didn't have anything close to this. oshawat00 62 — 5y
0
Nvm oshawat00 62 — 5y
Ad
Log in to vote
-1
Answered by 5 years ago

Maybe try using a local script

Answer this question