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

Frame becomes visible for everyone when someone touches brick, How to fix this?

Asked by 4 years ago

I wanted to make when i touch block Frame becomes visible and camera changes subject but something went wrong there`s the code

local Open = script.Parent.Open
local camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local closed = script.Parent.Closed

workspace.Shop1.TouchPart.Touched:Connect(function(plr)
    if Open.Value == false and closed.Value == true then
        script.Parent.Frame.Visible = true
        game.StarterGui.Inf.Frame.Visible = false
        game.StarterGui.ScreenGui.Menu.Visible = false
        game.StarterGui.ScreenGui.TextLabel.Visible = false
        camera.CameraType = Enum.CameraType.Scriptable
            camera.CameraSubject = workspace.Shop1.Cam1
            camera.CFrame = workspace.Shop1.Cam1.CFrame
        Open.Value = true
        closed.Value = false
        wait(.500)
        local HRP = workspace:FindFirstChild(player.Name):FindFirstChild("HumanoidRootPart")
        HRP.Anchored = true
        wait()
    end 
end)

i have 2 scripts like this but in the second one i fixed it but i don`t like it, Is there a way to make this better? (code in second script)

local Blocks = game.Workspace.BattleBlocks
local opened = script.Parent.Opened

for i, v in pairs(Blocks:GetChildren()) do
    v.Touched:Connect(function(hit)
        if hit.Name ~= "Handle" then
        if opened.Value == false then
            opened.Value = true
        local Gold1 = script.Parent.Battle.Gold
        local Gold2 = v.SurfaceGui.Gold
        local XP1 = script.Parent.Battle.XP
        local XP2 = v.SurfaceGui.XP
        local Weapon1 = script.Parent.Battle.Weapon
        local Weapon2 = v.SurfaceGui.Weapon
        local Boss1 = script.Parent["Battle with"]
        local Boss2 = v.SurfaceGui.Boss
        print(hit)
        if hit.Name ~= "Handle" then
        game.Players:FindFirstChild(hit.Parent.Name).PlayerGui.BattleGui.Battle.Visible = true
        end
        Gold1.Text = ""..Gold2.Text
        XP1.Text = ""..XP2.Text
        Weapon1.Text = ""..Weapon2.Text
        Boss1.Text = "Battle with "..Boss2.Text
        wait(3)
        end
        end
    end)
end

script.Parent.Exit.MouseButton1Click:Connect(function()
    script.Parent.Visible = false
    wait(3)
    opened.Value = false
end)

1 answer

Log in to vote
0
Answered by 4 years ago

The problem is that the script doesn't check if the localPlayer touches it; if someone or something touches it then it still activates.

local Open = script.Parent.Open
local camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local closed = script.Parent.Closed

workspace.Shop1.TouchPart.Touched:Connect(function(plr)
    if plr.Parent == player.Character then -- now it only activates if the localPlayer touches it
    if Open.Value == false and closed.Value == true then
        script.Parent.Frame.Visible = true
        game.StarterGui.Inf.Frame.Visible = false
        game.StarterGui.ScreenGui.Menu.Visible = false
        game.StarterGui.ScreenGui.TextLabel.Visible = false
        camera.CameraType = Enum.CameraType.Scriptable
            camera.CameraSubject = workspace.Shop1.Cam1
            camera.CFrame = workspace.Shop1.Cam1.CFrame
        Open.Value = true
        closed.Value = false
        wait(.500)
        local HRP = workspace:FindFirstChild(player.Name):FindFirstChild("HumanoidRootPart")
        HRP.Anchored = true
        wait()
    end 
    end
end)
0
Thank you! gggamer1921212 5 — 4y
Ad

Answer this question