the value didnt change and

at line 9
idk what the eror im not good at scripting
I need help to fix this local script:
while wait() do
local Distance = game.Workspace.Distance
local player = game.Players.LocalPlayer
local humanoid = player.Character:WaitForChild("Humanoid")
if humanoid.MoveDirection.Magnitude >= 0 then
local DFruits = {"Suke-Suke Fruit", "Bomb-Bomb Fruit"}
local part1 = player.Character:WaitForChild("HumanoidRootPart")
local part2 = game.Workspace.DevilFruitSpawner.SpawnedDFS:WaitForChild(DFruits).Handle
local Meters = (part1.Position - part2.Position).Magnitude
Distance.Value = math.floor(Meters)
end
end
2 Likes
Instance:WaitForChild() expects an instance name in string data type, not a table.
And also, can you describe what this piece of code supposed to do?
Here you are attempting to get a table using WaitForChild, without taking a string out of the table.
Use math.random to choose a part randomly. But I don’t know what you are trying to achieve, so please elaborate on us.
local part2 = game.Workspace.DevilFruitSpawner.SpawnedDFS:WaitForChild(DFruits[math.random(1, #DFruits)]).Handle
This code works if the fruit appears in the folder then the value shows the character distance from the fruit when suke fruit spawn the text change but if bomb fruit spawn the text didnt change
i can show the full code
Then, you can use Instance:FindFirstChild():
local Distance = game.Workspace.Distance
local Meters = 0
local player = game.Players.LocalPlayer
local humanoid = player.Character:WaitForChild("Humanoid")
while wait() do
if humanoid.MoveDirection.Magnitude >= 0 then
local DFruits = {"Suke-Suke Fruit", "Bomb-Bomb Fruit"}
local part1 = player.Character:WaitForChild("HumanoidRootPart")
local part2 = game.Workspace.DevilFruitSpawner.SpawnedDFS:FindFirstChild(DFruits[1]) or game.Workspace.DevilFruitSpawner.SpawnedDFS:FindFirstChild(DFruits[2])
if part2 then
Meters = (part1.Position - part2.Position).Magnitude
else
Meters = 0
end
Distance.Value = math.floor(Meters)
end
end
Code edited
Then, can you show the full code?
k but it just nill when bomb fruit spawn
Do you using a normal script to change the text of the text label?
ScreenShoot:


–in StarterGui
FullScript:
--Control(Local Script)--
local remote = game:GetService("ReplicatedStorage"):WaitForChild("DevilFruit") -- the remote devil fruit
local marketPlaceService = game:GetService("MarketplaceService") -- we get the marketplace service (we need it to check whether the player owns the notifier gamepass)
remote.OnClientEvent:Connect(function(Value) -- if the remoteeevent has been firecliented then
local PlayerGui = script.Parent
if Value == "NotifyDF" and marketPlaceService:UserOwnsGamePassAsync(game.Players.LocalPlayer.UserId, 18384171) then -- we check if the fireclient was supposed to make us notify that the df has been spawned, if so then we check whether the player has the gamepass
local clone = script.FruitNotifier:Clone()
clone.Parent = PlayerGui
local gui = PlayerGui.FruitNotifier
gui.Enabled = true
elseif Value == "UnotifyDF" and marketPlaceService:UserOwnsGamePassAsync(game.Players.LocalPlayer.UserId, 18384171) then -- we check if the fireclient was supposed remove the notifier text because the df was taken/despawned, if so then we check whether the player has the gamepass
local destroy = PlayerGui.FruitNotifier
destroy:Destroy()
end
end)
--Client(LocalScript)--
game.Workspace.Distance.Changed:Connect(function(value)
local player = game.Players.LocalPlayer
local gui = player:WaitForChild("PlayerGui")
local ui = gui:WaitForChild("FruitNotifier")
ui.FarAwayText.Text = game.Workspace.Distance.Value
end)
--DistanceScript(LocalScipt)--
while wait() do
local Distance = game.Workspace.Distance
local Meters = 0
local player = game.Players.LocalPlayer
local humanoid = player.Character:WaitForChild("Humanoid")
if humanoid.MoveDirection.Magnitude >= 0 then
local DFruits = {"Suke-Suke Fruit", "Bomb-Bomb Fruit"}
local part1 = player.Character:WaitForChild("HumanoidRootPart")
local part2 = game.Workspace.DevilFruitSpawner.SpawnedDFS:WaitForChild(DFruits[1]).Handle or game.Workspace.DevilFruitSpawner.SpawnedDFS:WaitForChild(DFruits[2]).Handle
if part2 then
Meters = (part1.Position - part2.Position).Magnitude
end
Distance.Value = math.floor(Meters)
end
end
no, and i find bug when i respawn gui not clone
I think you should consider changing the table into separate variables. WaitForChild() expects an instance not a table.
Do this:
local Suke-SukeFruit = “Suke-SukeFruit”
local Bomb-BombFruit = “Bomb-BombFruit”
local part2 = game.Workspace.DevilFruitSpawner.SpawnedDFS:WaitForChild(Suke-SukeFruit) and game.Workspace.DevilFruitSpawner.SpawnedDFS:WaitForChild(Bomb-BombFruit)
it didnt work when the fruit spawn the text didnt change
Hmmm… Maybe you shall consider… adding a model which is that fruit or adding a string value.
I constructed a sample place, and seems like you don’t spawn the fruit in workspace > DevilFruitSpawner > SpawnedDFS. That’s why your text label doesn’t update because distance script can’t find any object in specified path!
Also edited your distance code:
local Distance = game.Workspace.Distance
local Meters = 0
local player = game.Players.LocalPlayer
local humanoid = player.Character:WaitForChild("Humanoid")
local DFruits = {"Suke-Suke Fruit", "Bomb-Bomb Fruit"}
local part1 = player.Character:WaitForChild("HumanoidRootPart")
while wait() do
if humanoid.MoveDirection.Magnitude > 0 then
local part2 = game.Workspace.DevilFruitSpawner.SpawnedDFS:FindFirstChild(DFruits[1]) or game.Workspace.DevilFruitSpawner.SpawnedDFS:FindFirstChild(DFruits[2])
if part2 then
Meters = (part1.Position - part2.Position).Magnitude
else
Meters = 0
end
Distance.Value = math.floor(Meters)
end
end