Hello, I want to make a game exactly like a Buffet. So I’m checking if the player touches the top of the container with the food in it and the model that touches it is named “Bowl” then it will make a confirm frame visible. But for some reason, this script won’t work, When I touch the top of the container with the tool nothing happens…
(I know this might be a simple fix but I haven’t dealt with much frame.Visible = true recently.)
Heres the script I’m using:
> local part = script.Parent
> local Frame = script.Parent.Parent.Parent.Parent.StarterGui.ScreenGui.Frame
>
> part.Touched:Connect(function(hit)
> if hit.Name == "Bowl" then
> Frame.Visible = true
> end
> end)
StarterGui is what the name implies, what the player’s GUI starts as. You can’t just edit the StarterGui to edit the player’s GUI. Use Players:GetPlayerFromCharacter to get the player, then turn their frame visible. You shouldn’t be handling GUIs on the server though, but if you don’t know how to turn them on client-side, use your current method.
Code:
--//Services
local Players = game:GetService("Players")
--//Variables
local part = script.Parent
--//Functions
part.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player and hit.Name == "Bowl" then
player.PlayerGui.ScreenGui.Frame.Visible = true
end
end)
I am making this code assuming that this is a LocalScript
local Player = game:GetService('Players').LocalPlayer
local PlayerGui = Player.PlayerGui
local Part = script.Parent
Part.Touched:Connect(function(Part)
if Part.Name == 'Bowl' then
PlayerGui.ScreenGui.Frame.Visible = true
end
end)