Help - Trying to make a walk shop

Here is an image of the shop:

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

1 Like

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 :+1:

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)
1 Like

Thank you, doesnt work though
30charssssssss

Hmph, I’m not too sure. I’ve edited my OP. Perhaps give that a go?

i tested your script and it works perfectly on my end

did you put this on a localscript already?

1 Like

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

Yeah its a local script in starterplayerscripts, ;//

Just do character:WaitForChild(“HumanoidRootPart”). Also, that’s not a good way to proceed,

Last time, I’ve tried it and the magnitude wasn’t updating(idk why tho)

You need to do :

(game.Workspace[plr.Name]:FindFirstChild("HumanoidRootPart").Position - boostshop.Position).Magnitude

Nope, this does not work either, im not sure if this is because im getting errors with other GUI would this affect it?

Are you using this in startercharacterscripts?

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.