How do I reference a value inside of a localscript, inside a part from a localscript inside a startergui?
Are those scripts are LocalScripts?
yeah they both are local scripts
Iāll rephrase your question:
What you want, is to get the value of value
in the second script,
and pass it into the first script
Am I right?
Yeah, that is what I am trying to do.
The second script:
local thatValue = script.Value -- named it thatValue so it wont be confusing
clicker = script.Parent.ClickDetector -- i assume that the LocalScript with value in it is in the part
function onClicked(mouse)
clicker.MaxActivationDistance = 0 -- i dont know why are you assinging 2 values at the same time, but i assume thats right
value.Value = true -- assign thatValue's value to true
clicker.MaxActivationDistance = 32
end
script.Parent.ClickDetector.MouseClick:Connect(onClicked)
The first script:
wait() -- debounce
local value = -- define the value thats in the LocalScript
if value.Value == true then
mouse = game.Players.LocalPlayer:GetMouse()
mouse.Icon = "rbxassetid://46537754"
end
If any error occurs in the output, reply with the screenshot of it
How do you ādefine the value thatās in the LocalScriptā?
Set the path of the value.
In example:
local value = game.Workspace.CursorButton.LocalScript.Value -- assuming that the part(CursorButton) is in the workspace
A question, where does the 1st script belong?
Why are you not writing local?
The 1st script is belonging in the StarterGui
Its not necessary?
I mean, its optional when youāre writing it in the script itself(where no indentation is), and its needed when writing in an if
or function
space
Thanks!
Full code:
The second script:
local thatValue = game.Players.LocalPlayer.PlayerGui.LocalScript.Value
clicker = script.Parent.ClickDetector -- i assume that the LocalScript with value in it is in the part
function onClicked(mouse)
clicker.MaxActivationDistance = 0 -- i dont know why are you assinging 2 values at the same time, but i assume thats right
value.Value = true -- assign thatValue's value to true
clicker.MaxActivationDistance = 32
end
script.Parent.ClickDetector.MouseClick:Connect(onClicked)
The first script:
wait() -- debounce
local value = script.Value
if value.Value == true then
mouse = game.Players.LocalPlayer:GetMouse()
mouse.Icon = "rbxassetid://46537754"
end
Again, if any error occurs in the output, reply with the screenshot of it.
Thereās no errors, it just doesnāt work. The second script is in Workspace.
Just in workspace or any exact part?
Itās in workspace, CursorButton and it says on line 6 that value is an undefined global variable
Yes, it is an undefined value, since you havenāt called it outside the function.
Iāll rewrite the script, and while I do that, write out the exact name for the part and the script
In example:
-- the part: game:GetService("Workspace").CursorButton (since you've said that the script is in the workspace)
-- the first localscript: game:GetService("Workspace").CursorButton.LocalScript
-- the 2nd localscript: game.Players.LocalPlayer.PlayerGui.LocalScript
The part: first script: game:GetService(āWorkspaceā).CursorButton
first script: game:GetService(āWorkspaceā).CursorButton.Localscript
Second Script: game:GetService(āStarterGuiā).CursorChange
First script:
-- delete everyhting
Second script:
local p = script.Parent.Sound -- assuming that the Sound is in the PlayerGui; if not, set its' path to where it is.
p.Looped = false -- setting it to false because i assume its less than 5 seconds long
local thatScript = game:GetService("Workspace").CursorButton.LocalScript
local value = thatScript.Value
local clicker = script.Value
local mouse = game.Players.LocalPlayer:GetMouse()
thatScript.Parent.ClickDetector.MouseClick:Connect(function()
if value.Value == true then
value.Value = true -- assign thatValue's value to true, since the player clicked on the part
clicker.MaxActivationDistance = 32
p:Play()
mouse.Icon = "rbxassetid://46537754"
else
value.Value = false -- assign thatValue's value to false, since the player clicked on the part again
clicker.MaxActivationDistance = 32
-- not calling the sound because the value is false
end
end)
You would have to create a value inside the second script(dont name it, keep itsā name Value), and delete the first script since the function is inside of the second script.
Reply if nothing happens, or an error occurs.
If you want exactly 2 scripts to be made, reply with saying so.
update: changed the script since i used a different variable