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

A script that makes a Frame visible, output is visible, but i can't see frame. Why?

A script that makes a Frame visible, when testing it, property of the Frame "visible" is true but i can't see it

stepblock = game.Workspace:WaitForChild("housestep")
housemodel = game.Lighting.house
phone = game.StarterGui.phone.Frame.toggle
ftointeract = game.StarterGui.ui.Frame.ftointeract

print("working")

function lightOnFire(hit)
 if (hit.Parent:FindFirstChild("Humanoid") ~= nil) then
   phone.Disabled = true
 print("working2")
   ftointeract.Visible = true
 print("working3")
   end
end

stepblock.Touched:connect(lightOnFire)

2 comments

0

Note that working, working2, and working3 are printed in the output

0

why is there an upvote on this question

3 answers

✓ Accepted answer

A few things of note here.

Firstly, you shouldn't store anything that isn't related to lighting in game.Lighting, it should go into game.ReplicatedStorage if it needs to be replicated to the client at all times, or game.ServerStorage if it does not.

game.StarterGui is the template for all GUIs that get cloned into the player's Player.PlayerGui folder. Modifying it merely modifies the template.

In your BasePart.Touched listener, just so you're aware, this will fire when any part with a humanoid touches it. We also shouldn't assume that the part has a parent when the event listener fires. I'm going to assume you really wanted to check if it was any player that touched the part:

function onStepBlockTouched(touchPart)
	if not touchPart.Parent then
		return
	end

	local player = game.Players:GetPlayerFromCharacter(touchPart.Parent)

	if not player then
		return
	end

	-- Modify GUI stuff as needed.
end)

Additionally, RBXScriptSignal:connect() is deprecated, so you should prefer RBXScriptSignal:Connect().

You index the gui template inside StarterGui, while the gui that player sees is in their PlayerGui. This is a common mistake.

Put this script into a Script and parent it to the stepblock:

script.Parent.Touched:connect(function(hit)
	if hit.Parent.ClassName == "Model" then
		local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
		if not plr then return end
		plr.PlayerGui.phone.Frame.toggle.Disabled = true
		plr.PlayerGui.ui.Frame.ftointeract.Visible = true
	end
end)

6 comments

0

No, you don't want it parented to a block. You cannot change a player's PlayerGui server-side, you'd need to use a RemoteEvent. Additionally, you should not be assuming that the part that touched has a parent.

0

In order for a part to touch it, it has to be in workspace, thus it has to have a parent. It would literally have to be removed the same second it touches the stepblock to not have a parent.

0

yep

0

As for the "you cannot change a player's PlayerGui server-side", well... https://i.imgur.com/vKBOl3w.png

0

No. When the BasePart.Touched event fires, the part that touched is able to no longer have a parent. This is a common error. Do not assume it has a parent.

0

I should clarify: GUIs that replicated from game.StarterGui will not be replicated to the server, so the server will not see any player's GUIs that the server did not explicitly parent itself.

StarterGui should not be confused with the Player's PlayerGui, because when a player spawns their gui is cloned and moved from StarterGui which could effect all the gameplay,

you should use :GetPlayerFromCharacter() and change a few things in the script

local stepblock = workspace:WaitForChild("housestep")
local housemodel = game.Lighting.house

stepblock.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then
local ser =  game.Players:GetPlayerFromCharacter(hit.Parent).PlayerGui
   ser.phone.Frame.toggle.Disabled = true ser.ui.Frame.ftointinteract.Visible = true
   end end)

1 comment

0

You're assuming the part that touched still has a parent, and accessing the player's PlayerGui that touched, which you can't do without a RemoteEvent.

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