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

How to make a bool value change when the puck touches the script?

Asked by 4 years ago
Edited 4 years ago

I want a value to enable when the puck touches the stick heres what I have. The value is a Bool Value by the way. The script is a local

script.Parent.Touched:connect(function(Part)
  if Part.Name == "ball" then
    game.StarterPack.stick.HasPuck.Value = true
end

Whenever I touch the puck with the stick it dosen't enable. Is it not possible to do this?

0
is this a localscrit royaltoe 5144 — 4y
0
yes KronxGoat 50 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

It is very possible to do this, and is actually quite simple.

Instead of trying to find the value from StarterPack, I put the script in the puck and set the var bool to script.Parent.HasBall(the name of the bool). I then made a Touch function and here we are.

Make Sure The Script is not local

--Setting Variables
local Stick = script.Parent
local bool = script.Parent.HasBall

local puck = workspace.Ball

--Setting the bool Value to false(I am pretty sure this is not required)
bool.Value = false
print("bool is false")

--The function
puck.Touched:Connect(function(hit)
    if hit == Stick or hit.Parent == Stick then
        bool.Value = true
        print("bool is true")
    end
end)
0
it isnt working KronxGoat 50 — 4y
0
Is it in a server script or local doomblade_66 55 — 4y
0
server KronxGoat 50 — 4y
0
Maybe add me on disc my disc is JR#0542 KronxGoat 50 — 4y
0
Okay doomblade_66 55 — 4y
Ad

Answer this question