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

Change a value located in Game.Workspace.Player if your script is located in Game.Players.Player?

Asked by 7 years ago

I have a script that is located in Game.Players.NAMEOFTHEPLAYER.StarterGuis.Frame.Script and I need this script to interfear with a value located in Game.Workspace.NAMEOFTHEPLAYER.Humanoid . The problem is that it's not a simple script.Parent.Parent(etc) GUI. I know it's a little bit more complicated that that and I would like that someone answer my question, with a simple explaination please! (The explaination because I would like to know how it works and how to do it myself the next time.)

2 answers

Log in to vote
1
Answered by 7 years ago

Well, if I understand what you meant. script.Parent would be the frame, script.Parent.Parent, would be PlayerGui and finally, script.Parent.Parent.Parent would be the player. Now, the player has a property called "Character" (Which is nil if they don't have a character loaded in) so the way you'd get the value through this is: script.Parent.Parent.Parent.Character.Humanoid.Value This is of course with no checks, and could error! Now, if this is a localscript and you're trying to get the LocalPlayer's character, DO NOT USE REPEATS OF script.Parent! Instead use: game:GetService'Players'.LocalPlayer.Character It's much more reliable; if the script gets movedit will not error.

For scripts to not use .Parent repeatedly, you could use a findFirstChild with a randomized script name.

Finished:

--Script
script.Parent.Parent.Parent.Character.Humanoid.Value.Value = "A"
--LocalScript
game:GetService'Players'.LocalPlayer.Character.Humanoid.Value.Value = "A"
--I recommend adding checks, like if localPlayer.Character then --etc
0
If I missed anything or misunderstood anything, please tell me. fireboltofdeathalt 118 — 7y
0
This is better than mine, and I didnt know there was a property called Character, so thats new. Good job dude, +1 Ex_plore 62 — 7y
0
Thank you! fireboltofdeathalt 118 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

You could get the name of the player the script is in, then use a for loop to look for that player and have it go through that player and change the value.

for example,

Name=script.Parent.Parent.Parent --Here you need to get the player name, this might not work since you said its not a simple script.Parent.Parent GUI

for i,v in pairs(game.Workspace) do
Human=v:FindFirstChild("Humanoid")
if v.Name==Name and Human==true then--This checks if v in the for loop is the player and if its an actual player or a part named after the player. V is the thing it is checking
 v.Humanoid--I am assuming this is the place you want to change the value or close to it

Hope this kind of helped, it probably didn't, but hey it was a suggestion.

Answer this question