Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

###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.

4 comments

0

but you didnt really answer his question: "How do you change the value of a variable outside of your script?"

0

But his commented line 8 points out the problem.

0

well yeah, i guess.

0

Thanks! This helped me get the solution

This discussion is preserved as it was. New answers, comments, and votes are closed.