You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve?
An arrow that points to a part if a player doesn’t have a Tool.
- What is the issue?
The issue is it doesn’t work how it should, it point to the part but sometimes it works and sometimes it doesn’t!
- What solutions have you tried so far?
Finding a solution!
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local ArrowModel = game.ReplicatedStorage:WaitForChild("ArrowModel"):Clone()
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
ArrowModel.Name = player.Name.."'s Arrow"
game:GetService("RunService").RenderStepped:Connect(function()
for i, v in pairs(player.Character:GetChildren()) do
for i2, v2 in pairs(player.Backpack:GetChildren()) do
if v:IsA("Tool") or v2:IsA("Tool") then
ArrowModel.Parent = game.ReplicatedStorage
player.PlayerGui.BuyBoxingGloves.ImageLabel:TweenPosition(UDim2.new(0.5, 0,-0.5, 0),Enum.EasingDirection.In,Enum.EasingStyle.Linear,0.2)
player.PlayerGui.BuyBoxingGloves.ImageLabel.Visible = false
else
ArrowModel.Parent = workspace
player.PlayerGui.BuyBoxingGloves.ImageLabel:TweenPosition(UDim2.new(0.5, 0,0.2, 0),Enum.EasingDirection.In,Enum.EasingStyle.Linear,0.2)
player.PlayerGui.BuyBoxingGloves.ImageLabel.Visible = true
ArrowModel.PrimaryPart.CFrame = CFrame.new(char.HumanoidRootPart.Position, workspace.OpenShop.Position)
end
end
end
end)
Thank you!
The problem is that player.Backpack:GetChildren()
could be an empty table. Because it’s empty it won’t loop.
To solve this just merge the 2 tables (it’s also more efficient this way)
I wrote this on mobile so there may be errors
local ArrowModel = game.ReplicatedStorage:WaitForChild("ArrowModel"):Clone()
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
ArrowModel.Name = player.Name.."'s Arrow"
game:GetService("RunService").RenderStepped:Connect(function()
for i, v in pairs(table.pack(table.unpack(player.Character:GetChildren()), table.unpack(player.Backpack:GetChildren()))) do
if v:IsA("Tool") then
ArrowModel.Parent = game.ReplicatedStorage
player.PlayerGui.BuyBoxingGloves.ImageLabel.Visible = true
player.PlayerGui.BuyBoxingGloves.ImageLabel:TweenPosition(UDim2.new(0.5, 0,0.2, 0),Enum.EasingDirection.In,Enum.EasingStyle.Linear,0.2)
break -- break the for loop for efficiency
else
ArrowModel.Parent = workspace
player.PlayerGui.BuyBoxingGloves.ImageLabel:TweenPosition(UDim2.new(0.5, 0,-0.2, 0),Enum.EasingDirection.In,Enum.EasingStyle.Linear,0.2)
player.PlayerGui.BuyBoxingGloves.ImageLabel.Visible = false
ArrowModel.PrimaryPart.CFrame = CFrame.new(char.HumanoidRootPart.Position, workspace.OpenShop.Position)
end
end
end)
It’s kinda long but works so yeah (and also more efficient)
It’s missing a ‘)’ I just edited it copy the new one
Just testing if it is working sorry
Nah it’s fine. Also, I capitalized ‘Pack’ in ‘BackPack’. How dumb of me.
Oh lol, no worries anyways I think it is working! Thank you so much!
I have an error when ever I like equip the tool the arrow shows back up how could I fix it?
I am getting loads of the same errors
Oh it’s because the for loop is checking each and seting the arrows. I can fix it. 1 moment please
Okay thank you so much, no worries!
local ArrowModel = game.ReplicatedStorage:WaitForChild("ArrowModel"):Clone()
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
ArrowModel.Name = player.Name.."'s Arrow"
game:GetService("RunService").RenderStepped:Connect(function()
local a = false
for i, v in ipairs(table.pack(table.unpack(player.Character:GetChildren()), table.unpack(player.Backpack:GetChildren()))) do
if v:IsA("Tool") then
a = true
break
end
end
if a then
ArrowModel.Parent = game.ReplicatedStorage
player.PlayerGui.BuyBoxingGloves.ImageLabel.Visible = true
player.PlayerGui.BuyBoxingGloves.ImageLabel:TweenPosition(UDim2.new(0.5, 0,0.2, 0),Enum.EasingDirection.In,Enum.EasingStyle.Linear,0.2)
else
ArrowModel.Parent = workspace
player.PlayerGui.BuyBoxingGloves.ImageLabel:TweenPosition(UDim2.new(0.5, 0,-0.2, 0),Enum.EasingDirection.In,Enum.EasingStyle.Linear,0.2)
player.PlayerGui.BuyBoxingGloves.ImageLabel.Visible = false
ArrowModel.PrimaryPart.CFrame = CFrame.new(char.HumanoidRootPart.Position, workspace.OpenShop.Position)
end
end)
Still giving me loads of errors and is making the game lag a lot.
Can you add print(i,v) after line 10 and let me see the output
Found the problem. Turn pairs into ipairs and it should work.
1 Like
Its working and its not lagging the only problem is now that if i equip the tool the arrow shows back
Because when you unequip a tool it goes into player.Backpack and when you like equip it it goes inside the players model!