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

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

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

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)

1 comment

0

Thank you!

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