Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to script if an item is not on the Workplace?

Asked by 9 years ago

Hi, I am trying to script a bowling ball return which has an automatic load up for the next ball - I am just wondering how to script the ball return button which tells the customer if the ball return is broken (if the ball is not appearing on the Workspace).

This script which I would be thinking that would work, when the ball is visible but what if it doesn't?

if script.Parent.Parent.Ball2 then
script.Parent.SurfaceGui.TextLabel.Text = "Out of use!
end

If you want more explanation, please comment below!

Thanks!

0
FYI: the way you did it (If Hierarchy is right) would only work IF that Ball2 existed. alphawolvess 1784 — 9y

2 answers

Log in to vote
0
Answered by 9 years ago

You want to use FindFirstChild() to do this, FindFirstChild basically does what it's name says, it will find the child of something(You use the Argument to tell what it's looking for) This is what your code should look like -

if game.Workspace.FindFirstChild("Ball2") then
script.Parent.SurfaceGui.TextLabel.Text = "Out of use!"
end

If you didn't notice, you did not fully quotation your Out of Use string. I did this for you, do not forget to use close quotation marks!

0
I assumed that you meant Workspace not Workplace. If Workplace is some sort of model, Tell me and I will fix the script if you don't know how to! alphawolvess 1784 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

Hi, Thanks for getting back to me. I have got the full script here which I have added your code into it - the main bit of the script like "Please wait.." works fine, but I have tested this when there is no ball on the Workspace and there is a problem which is that the light of the button has not been changed and the text has not changed either. So, I am just wondering if I might've put in the wrong place or do you think I have added something extra which it wont work.

Anyways, here is the full code.

function onClicked()
script.Parent.ClickDetector.MaxActivationDistance = 0
script.Parent.BrickColor = BrickColor.new (21)
m = script.Parent.Parent.Ball1:Clone()
m.Parent = game.Workspace
m.Handle.CanCollide = true
m.Handle.Anchored = false
m.Handle.Transparency = 0
m.Enabled = true
script.Parent.SurfaceGui.TextLabel.Text = "Please wait." -- This works fine!
wait(1)
script.Parent.SurfaceGui.TextLabel.Text = "Please wait.." -- This works fine!
wait(1)
script.Parent.SurfaceGui.TextLabel.Text = "Please wait..." -- This works fine!
wait(1)
script.Parent.SurfaceGui.TextLabel.Text = "Please wait." -- This works fine!
wait(1)
script.Parent.SurfaceGui.TextLabel.Text = "Please wait.." -- This works fine!
wait(1)
script.Parent.SurfaceGui.TextLabel.Text = "Please wait..." -- This works fine!
wait(1)
script.Parent.SurfaceGui.TextLabel.Text = "Please wait." -- This works fine!
wait(1)
script.Parent.SurfaceGui.TextLabel.Text = "Please wait.." -- This works fine!
wait(1)
script.Parent.SurfaceGui.TextLabel.Text= "Regen Ball" -- This works fine!
script.Parent.ClickDetector.MaxActivationDistance = 30
script.Parent.BrickColor = BrickColor.new (28)

if game.Workspace.FindFirstChild("Ball1") then  -- This doesn't work, unless if I have put it in the wrong place of the script.
script.Parent.SurfaceGui.TextLabel.Text = "Out of use!"
script.Parent.BrickColor = BrickColor.new (21) -- I have added this a bit extra including this 3 lined code!

end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)
0
Anyone? BenHall4433 0 — 9y

Answer this question