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
01 | local DropColor = script.Parent.Parent.Parent.Values.DropColor.Value |
02 | local Floor = script.Parent.Parent.Parent.MainItems.Floor |
03 | local OwnerValue = script.Parent.Parent.Parent.Values.OwnerValue |
04 |
05 | for i,v in pairs (script.Parent.Buttons:GetChildren()) do |
06 | v.ClickDetector.MouseClick:connect( function () |
07 | DropColor = v.BrickColor |
08 | script.Parent.Showing.BrickColor = v.BrickColor |
09 | Floor.BrickColor = v.BrickColor |
10 | end ) |
11 | end |
Script #2 for the Materializer
1 | for i,v in pairs (script.Parent.Buttons:GetChildren()) do |
2 | v.ClickDetector.MouseClick:connect( function () |
3 | script.Parent.Parent.Parent.Values.MaterialValue.Value = v.Material.Name |
4 | script.Parent.Showing.Material = v.Material.Name |
5 | script.Parent.Parent.Parent.MainItems.Floor.Material = v.Material.Name |
6 | end ) |
7 | end |
You can add an if statement that checks if the player who clicked is the owner.
01 | local DropColor = script.Parent.Parent.Parent.Values.DropColor.Value |
02 | local Floor = script.Parent.Parent.Parent.MainItems.Floor |
03 | local OwnerValue = script.Parent.Parent.Parent.Values.OwnerValue |
04 |
05 | for i,v in pairs (script.Parent.Buttons:GetChildren()) do |
06 | v.ClickDetector.MouseClick:Connect( function (player) -- parameter has the value of player who clicked it |
07 | if player.Name = = OwnerValue.Value |
08 | DropColor = v.BrickColor |
09 | script.Parent.Showing.BrickColor = v.BrickColor |
10 | Floor.BrickColor = v.BrickColor |
11 | end |
12 | end ) |
13 | end |
1 | for i,v in pairs (script.Parent.Buttons:GetChildren()) do |
2 | v.ClickDetector.MouseClick:Connect( function (player) |
3 | if player.Name = = OwnerValue.Value then |
4 | script.Parent.Parent.Parent.Values.MaterialValue.Value = v.Material.Name |
5 | script.Parent.Showing.Material = v.Material.Name |
6 | script.Parent.Parent.Parent.MainItems.Floor.Material = v.Material.Name |
7 | end |
8 | end ) |
9 | end |
Recommendation(s):
It's also better to use :Connect instead of :connect as that is deprecated/outdated.
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.
01 | local DropColor = script.Parent.Parent.Parent.Values.DropColor.Value |
02 | local Floor = script.Parent.Parent.Parent.MainItems.Floor |
03 | local OwnerValue = script.Parent.Parent.Parent.Values.OwnerValue |
04 |
05 | for i,v in pairs (script.Parent.Buttons:GetChildren()) do |
06 | v.ClickDetector.MouseClick:connect( function (plr) |
07 | if plr.Name = = OwnerValue then |
08 | DropColor = v.BrickColor |
09 | script.Parent.Showing.BrickColor = v.BrickColor |
10 | Floor.BrickColor = v.BrickColor |
11 | end |
12 | end ) |
13 | end |
I would assume you have these scripts in the same directory or you have them in the same script.
01 | local OwnerValue = script.Parent.Parent.Parent.Values.OwnerValue |
02 | for i,v in pairs (script.Parent.Buttons:GetChildren()) do |
03 | v.ClickDetector.MouseClick:connect( function (plr) |
04 | if plr.Name = = OwnerValue then |
05 | script.Parent.Parent.Parent.Values.MaterialValue.Value = v.Material.Name |
06 | script.Parent.Showing.Material = v.Material.Name |
07 | script.Parent.Parent.Parent.MainItems.Floor.Material = v.Material.Name |
08 | end |
09 | end ) |
10 | end |