Im trying to make it so if you are … Close to the shop a GUI Opens, if not the GUI is closed,
Here is my code in startplayer:
local rs = game:GetService("RunService")
local plr = game.Players.LocalPlayer
local character = plr.Character or plr.CharacterAdded:wait()
local boostshop = game.Workspace.Boosts.UpgradePart
rs.Heartbeat:Connect(function()
local boostmag = (character.HumanoidRootPart.Position - boostshop.Position).Magnitude
if boostmag < 5 then
plr.PlayerGui.Main2.BoostFrame.Visible = true
else
plr.PlayerGui.Main2.BoostFrame.Visible = false
end
end)
The error:
Line 8, HumanodiRootPart is not a valid member of model
Well try this. Before your script beings running code put a wait timer for about 3 seconds to give it a load time then instead of waiting for characterAdded try using plr.Character. And if that doesn’t work say if
plr ==nil then return end
local Player = game:GetService("Players").LocalPlayer
repeat wait(.05) until Player.Character ~= nil
local Character = Player.Character
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local BoostShop = game:GetService("Workspace"):WaitForChild("Boosts")["UpgradePart"]
game:GetService("RunService").Heartbeat:Connect(function())
local Mag = (HumanoidRootPart.Position - BoostShop.Position).Magnitude
if Mag < 5 then
Player["PlayerGui"]["Main2"]["BoostFrame"].Visible = true
else
Player["PlayerGui"]["Main2"]["BoostFrame"].Visible = false
end
end)
What I would do is add a invisible cancollide part then set it so when the players touches the gui visible then when they are not the gui is not visible
Yes, i just added a print(boostmag) but that isnt printing, and print(“test”) just below where the function starts wont run; indicating that the function is not running.