So i am trying to make a ATM players can rob to get some cash, and i ran into problems with 2 scripts. I got feedback and someone helped me fixed the first one, however the UI script is acting up.
local inputservice = game:GetService("UserInputService")
inputservice.InputBegan:connect(function(i,g)
if i.UserInputType == Enum.UserInputType.Keyboard then
if i.KeyCode == Enum.KeyCode.E then
for _,Door in pairs(workspace.Shops:GetChildren()) do
local Mag = (Door.Center.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude
if Mag <= Door.Range.Value then
Door.Event:FireServer()
break
end
end
end
end
end)
while true do
script.Parent.ImageLabel.Visible = false
for _,Door in pairs(workspace.Shops:GetChildren()) do
local Mag = (Door.Center.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude
if Mag <= Door.Range.Value then
local D3ToD2 = workspace.CurrentCamera:WorldToScreenPoint(Door.Center.Position)
script.Parent.ImageLabel.Visible = true
script.Parent.ImageLabel.Position = UDim2.new(0,D3ToD2.X,0,D3ToD2.Y,0)
break
end
end
wait()
end
Here are the Output logs of the error:
[19:25:34.586 - HumanoidRootPart is not a valid member of Model]
(rbxopenscript://www.dummy.com/dummy?
scriptGuid=%7B3362D3D0-1795-46E1-9D2C-
801ABF5B2B60%7D&gst=2#21)
19:25:34.588 - Stack Begin
[19:25:34.589 - Script
'Players.AidanPlaysYT_Real.PlayerGui.PutinStarterGui.LocalScript',
Line 21](rbxopenscript://www.dummy.com/dummy?
scriptGuid=%7B3362D3D0-1795-46E1-9D2C-
801ABF5B2B60%7D&gst=2#21)
19:25:34.590 - Stack End
And the lines that are erroring: 'Players.AidanPlaysYT_Real.PlayerGui.E To Rob (ATM).LocalScript', Line 21
ResponseBody: HumanoidRootPart is not a valid member of Model
'Workspace.Shops.Store.ShopMain', Line 7
ResponeBody: PutinStarterGui is not a valid member of PlayerGui
can you also help me with the UI script. It is acting up.
local inputservice = game:GetService("UserInputService")
inputservice.InputBegan:connect(function(i,g)
if i.UserInputType == Enum.UserInputType.Keyboard then
if i.KeyCode == Enum.KeyCode.E then
for _,Door in pairs(workspace.Shops:GetChildren()) do
local Mag = (Door.Center.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude
if Mag <= Door.Range.Value then
Door.Event:FireServer()
break
end
end
end
end
end)
while true do
script.Parent.ImageLabel.Visible = false
for _,Door in pairs(workspace.Shops:GetChildren()) do
local Mag = (Door.Center.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude
if Mag <= Door.Range.Value then
local D3ToD2 = workspace.CurrentCamera:WorldToScreenPoint(Door.Center.Position)
script.Parent.ImageLabel.Visible = true
script.Parent.ImageLabel.Position = UDim2.new(0,D3ToD2.X,0,D3ToD2.Y,0)
break
end
end
wait()
end
Judging by how you wrote this code. I’m going to assume you aren’t using any sort of system that wouldn’t reload your client code every time the player dies. This may not fix it but I suggest not putting HumanoidRootPart in the inputBegan event.
local playerObject = game.Players.LocalPlayer
local characterObject = playerObject.Character or playerObject.CharacterAdded:Wait()
local humanoidRootPart = characterObject:WaitForChild("HumanoidRootPart")
and just use that when getting the humanoid root part.
Edit: Oh, that is actually the problem. In a whilte true do your client loads before your humanoidrootpart is created. Add that to the top of your script and it should work.