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

how to make this Colorizer and Materializer in a tycoon work only for a owner of the tycoon?

So the Colorizer and Materializer have buttons to click and i wanna know how to set it to where the other players cant come in the tycoon and mess around with that if they are not the owner.

setting both scripts up to where it has a owner value and only the owner can mess with these buttons in the tycoon itself.

Script #1 for the Colorizer

local DropColor = script.Parent.Parent.Parent.Values.DropColor.Value
local Floor = script.Parent.Parent.Parent.MainItems.Floor
local OwnerValue = script.Parent.Parent.Parent.Values.OwnerValue

for i,v in pairs(script.Parent.Buttons:GetChildren()) do
	v.ClickDetector.MouseClick:connect(function()
		DropColor = v.BrickColor
		script.Parent.Showing.BrickColor = v.BrickColor
		Floor.BrickColor = v.BrickColor
	end)
end

Script #2 for the Materializer

for i,v in pairs(script.Parent.Buttons:GetChildren()) do
	v.ClickDetector.MouseClick:connect(function()
		script.Parent.Parent.Parent.Values.MaterialValue.Value = v.Material.Name
		script.Parent.Showing.Material = v.Material.Name
		script.Parent.Parent.Parent.MainItems.Floor.Material = v.Material.Name 
	end)
end

2 answers

✓ Accepted answer

You can add an if statement that checks if the player who clicked is the owner.

local DropColor = script.Parent.Parent.Parent.Values.DropColor.Value
local Floor = script.Parent.Parent.Parent.MainItems.Floor
local OwnerValue = script.Parent.Parent.Parent.Values.OwnerValue

for i,v in pairs(script.Parent.Buttons:GetChildren()) do
    v.ClickDetector.MouseClick:Connect(function(player) -- parameter has the value of player who clicked it
	if player.Name == OwnerValue.Value
      		DropColor = v.BrickColor
  		script.Parent.Showing.BrickColor = v.BrickColor
       		Floor.BrickColor = v.BrickColor
	end
    end)
end
for i,v in pairs(script.Parent.Buttons:GetChildren()) do
    v.ClickDetector.MouseClick:Connect(function(player)
	if player.Name == OwnerValue.Value then
      	  script.Parent.Parent.Parent.Values.MaterialValue.Value = v.Material.Name
       	 script.Parent.Showing.Material = v.Material.Name
      	  script.Parent.Parent.Parent.MainItems.Floor.Material = v.Material.Name 
	end
    end)
end

Recommendation(s):

It's also better to use :Connect instead of :connect as that is deprecated/outdated.

2 comments

0

Thank you so much and now i understand about the :Connect and :connect

0

You're welcome!

Okay so, to make the colorizer and materializer work when the owner of the tycoon clicks them would be by making a check/if statement to see if the player is the owner of the tycoon. Here's the fixed version:

I assume the ownervalue is the player's name that owns the tycoon.

local DropColor = script.Parent.Parent.Parent.Values.DropColor.Value
local Floor = script.Parent.Parent.Parent.MainItems.Floor
local OwnerValue = script.Parent.Parent.Parent.Values.OwnerValue

for i,v in pairs(script.Parent.Buttons:GetChildren()) do
    v.ClickDetector.MouseClick:connect(function(plr)
	   if plr.Name == OwnerValue then
	        DropColor = v.BrickColor
	        script.Parent.Showing.BrickColor = v.BrickColor
	        Floor.BrickColor = v.BrickColor
	   end
    end)
end

I would assume you have these scripts in the same directory or you have them in the same script.

local OwnerValue = script.Parent.Parent.Parent.Values.OwnerValue
for i,v in pairs(script.Parent.Buttons:GetChildren()) do
    v.ClickDetector.MouseClick:connect(function(plr)
	   if plr.Name == OwnerValue then
	        script.Parent.Parent.Parent.Values.MaterialValue.Value = v.Material.Name
	        script.Parent.Showing.Material = v.Material.Name
	        script.Parent.Parent.Parent.MainItems.Floor.Material = v.Material.Name 
	   end
    end)
end

2 comments

0

"I assume the ownervalue is the player's name that owns the tycoon." = yes it is and also there is a issue with the first script on line 7, something with the "="

0

Oh yeah I didn't see that, you have to add another = in a if statement.

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