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

[SOLVED] How to make owner only door, but only the owner of the tycoon can press the button?

I have made a tycoon game where i got owner only door with a button, the button works how it should but the thing i also want there is to make it so only the tycoon owner can press it and make it so it does something, i can show my script there too

local enabled = true
local lasers = script.Parent.Lasers
local button = script.Parent.Button
local ownerValue = script.Parent.Parent.Parent.Values.OwnerValue

button.ClickDetector.MouseClick:Connect(function()
	if enabled == true then
		enabled = false
		lasers.Transparency = 0.8
		lasers.CanCollide = false 
	else
		if enabled == false then
			enabled = true
			lasers.Transparency = 0
			lasers.CanCollide = true
		end
	end
end)

lasers.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if ownerValue.Value ~= player then
			if enabled == true then
				hit.Parent:FindFirstChild("Humanoid").Health = 0
			else
				return end
		end
	end
end)

1 answer

✓ Accepted answer

Fortunately, the ClickDetector.MouseClick has a parameter of the player who clicked the ClickDetector.

local Players = game:GetService("Players")

local enabled = true
local lasers = script.Parent.Lasers
local button = script.Parent.Button
local ownerValue = script.Parent.Parent.Parent.Values.OwnerValue

lasers.CanCollide = false -- making it non collideable so it acts like a real lazer

button.ClickDetector.MouseClick:Connect(function(playerWhoClicked)
	if ownerValue.Value == playerWhoClicked then
		if enabled == true then
			enabled = false
			lasers.Transparency = 0.8
		else
			enabled = true
			lasers.Transparency = 0
		end
	end
end)

lasers.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChildOfClass("Humanoid") then
		local player = Players:GetPlayerFromCharacter(hit.Parent)
		if ownerValue.Value ~= player then
			hit.Parent:FindFirstChild("Humanoid").Health = 0
		end
	end
end)

1 comment

0

Thank you, this helped me!

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