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 6 years ago
Edited 6 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 6 years ago
Edited 6 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 — 6y
0
But his commented line 8 points out the problem. User#19524 175 — 6y
0
well yeah, i guess. Operation_Meme 890 — 6y
0
Thanks! This helped me get the solution CoosBuckett 10 — 6y
Ad

Answer this question