Problem with script

The names in the condition match, but the script does not work.
I think the problem is in this line → TycoonOwner == hit.Parent.Parent.Name

Script.

local TycoonOwner = script.Parent.Parent.Parent.Parent.Values.OwnerValue.Value
print(TycoonOwner)
local Soil = game.workspace.Soil
local planted = false
local readytogrow = false

script.Parent.Touched:Connect(function(hit)
	
	print(hit.Parent.Parent.Name)
 
	if hit.Name == 'Blade' and  readytogrow == false  then
	     readytogrow = true
	     script.Parent.Material = Soil.Material2.Value
    
->	elseif hit.Name == 'Rice'  and planted == false and TycoonOwner == hit.Parent.Parent.Name then
	     planted = true
	     local Seedling = game.ReplicatedStorage.Seeds:FindFirstChild(hit.Name):Clone()
	     Seedling.Parent = script.Parent
		 Seedling:SetPrimaryPartCFrame(script.Parent.Pos.CFrame)

image
image

Thank you.

1 Like

Once the code is started, TycoonOwner only contains the value of OwnerValue as it appeared, but not as it will appear in the future. Putting OwnerValue.Value into a variable only copies the value to that variable. Eventually, when OwnerValue.Value is changed, OwnerValue still retains the previous owner, and it has to be changed.

e.g…

-- let's say, the contents of SomeStringValue before the script is loaded is "__noplayer"
local Username = SomeStringValue.Value -- What the script saw as it started
print(Username, SomeStringValue.Value) -- __noplayer __noplayer

-- at some point, a player joins and we assume it gets updated to the StringValue:
SomeStringValue.Value = "xe44444"

print(Username, SomeStringValue) -- __noplayer xe44444

-- Username must be updated:
Username = SomeStringValue.Value

print(Username, SomeStringValue) -- xe44444 xe44444
-- 

Consider only referencing the OwnerValue object itself, and every time you compare the player’s name to said object’s value, do TycoonOwner.Value == hit.Parent.Parent.Name.

2 Likes

Thanks for the tutorial and thanks for solving the problem.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.