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

Why can't I change a variable from a different script?

Asked by 5 years ago

I tried making a currency and a minigame and what is supposed to happen is that if you get first, you would get that currency, but it never works.

local w = game.ServerScriptService.v:FindFirstChild(Wins)
local p = 0
if workspace.Parkour.PWalls.Winplat.Touched:Connect(FindFirstChild("Humanoid")) and p < 1 then
 w = w + 1
 p = p + 1
else
    p = p + 1
end

If anyone could help me, that would be great.

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Access the value, not the int itself. When using FindFirstChild the correct syntax is (" "), since you're searching for a name.

local w = game.ServerScriptService.v:FindFirstChild("Wins")
local p = 0
if workspace.Parkour.PWalls.Winplat.Touched:Connect(FindFirstChild("Humanoid")) and p < 1 then
    w.Value = w.Value + 1
    p = p + 1
else
p = p + 1
end

I think this is what you want though, the if statement will only run once, if you put it into a touched function it will watch for the touch.

local w = game.ServerScriptService.v:FindFirstChild("Wins")
local t = FindFirstChild("Humanoid")
local p = 0

workspace.Parkour.PWalls.Winplat.Touched:Connect(function(t)
    if p < 1 then
        w.Value = w.Value + 1
        p = p + 1
    else
        p = p + 1
    end
end)
0
You forgot to say that he didn't change Wins into "Wins" Overscores 381 — 5y
0
I corrected it but forgot to mention it, thanks. DinozCreates 1070 — 5y
0
Thank you! Sunetro 0 — 5y
0
Why is the last end underlined? Sunetro 0 — 5y
View all comments (6 more)
0
There was one more issue i missed, i forgot to add function DinozCreates 1070 — 5y
0
now it says "expected ')' to close '(' at column 58, got '(' Sunetro 0 — 5y
0
Are you using the first or second one? DinozCreates 1070 — 5y
0
The second one. Sunetro 0 — 5y
0
Interesting! You may not be able to use FindFirstChild as a parameter, try what ive just editted. DinozCreates 1070 — 5y
0
FindFirstChild is underlined in blue. Sunetro 0 — 5y
Ad

Answer this question