Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 1 year ago
Edited 1 year ago

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

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

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)
0
Thank you, this helped me! Samcek_God234 9 — 1y
Ad

Answer this question