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

How do you change the value of a variable outside of your script?

Asked by 5 years ago
Edited 5 years ago

I'm trying to make it so that whenever touch pad is touched, the script finds the players name and assigns it to the Owner StringValue and then prints the owners name. So far it prints the owners name, however the Owner StringValue remains unchanged. What am I doing wrong?

local touchpad = Tycoon.Entrance.touchpad
local owner = game.Workspace.Tycoon.Owner.Value

    local function steppedOn(part)
    local player = part.Parent
        if game.Players:GetPlayerFromCharacter(player) then
        local player = game.Players:GetPlayerFromCharacter(player)
        owner = player -- Supposed to make the Owner.Value equal to the player
        print(owner)
    end
end

touchpad.Touched:connect(steppedOn)

Thanks

1 answer

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

This is because of line 2. You’re setting owner to the value of the Owner object at the time of assignment. Assuming it’s an ObjectValue and the Value is nil, line 2 would be the same as:

local owner = nil

To fix this, remove the .Value.

Line 2:

local owner = game.Workspace.Tycoon.Owner

Line 8:

owner.Value = player

Check out my question about this common mistake here.

0
but you didnt really answer his question: "How do you change the value of a variable outside of your script?" Operation_Meme 890 — 5y
0
But his commented line 8 points out the problem. User#19524 175 — 5y
0
well yeah, i guess. Operation_Meme 890 — 5y
0
Thanks! This helped me get the solution CoosBuckett 10 — 5y
Ad

Answer this question