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

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

Asked by
ziploz 7
6 years ago

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)

0
Note that working, working2, and working3 are printed in the output ziploz 7 — 6y
0
why is there an upvote on this question GingeyLol 338 — 6y

3 answers

Log in to vote
0
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago

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().

Ad
Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
6 years ago

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)
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. Avigant 2374 — 6y
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. Amiaa16 3227 — 6y
0
yep GingeyLol 338 — 6y
0
As for the "you cannot change a player's PlayerGui server-side", well... https://i.imgur.com/vKBOl3w.png Amiaa16 3227 — 6y
View all comments (2 more)
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. Avigant 2374 — 6y
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. Avigant 2374 — 6y
Log in to vote
0
Answered by
GingeyLol 338 Moderation Voter
6 years ago
Edited 6 years ago

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)
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. Avigant 2374 — 6y

Answer this question