#how i can transfer 'hit' to 'Change' function?

1 messages · Page 1 of 1 (latest)

prime crypt
#
task.wait(1)
bindable = workspace.Intersection.Detector.power
IsPart = false
function ToggleGUI(hit)
local Player = game:GetService("Players")
    local frame = Player.LocalPlayer.PlayerGui.SurfaceGui.Frame
    if frame.Visible == false then
        frame.Visible = true
    end
end
function Change(power)
    if hit == "RedPart" and IsPart == true then
        print(power)
        print(hit)
    end
end
function Detect(hit)
        local str = string.sub(hit.Name, -4, -1)
        if str == "Part" then
            ToggleGUI(hit)
            IsPart = true
        else
            task.wait(0.01)
        end
end
workspace.Intersection.Detector.Touched:Connect(Detect)
bindable.Event:Connect(Change)

so i need thats Detect function somehow transfer hit to change, i guess i need two args(or not) but im dont know how to correct transfer it

bronze sun
#

Bro just pass it in a a parameter

prime crypt
bronze sun
#

Just seperate by a comma

#

Change(power, hit)

prime crypt
bronze sun
#

Send me what you did

#

Also when you call the function you need to pass on both parameters

prime crypt
# bronze sun Send me what you did
task.wait(1)
bindable = workspace.Intersection.Detector.power
IsPart = false
function ToggleGUI(hit)
local Player = game:GetService("Players")
    local frame = Player.LocalPlayer.PlayerGui.SurfaceGui.Frame
    if frame.Visible == false then
        frame.Visible = true
    end
end
function Change(power,hit)
    if hit == "RedPart" and IsPart == true then
        print(power)
        print(hit)
    end
end
function Detect(hit)
        local str = string.sub(hit.Name, -4, -1)
        if str == "Part" then
            ToggleGUI(hit)
            Change(hit)
            IsPart = true
        else
            task.wait(0.01)
        end
end
workspace.Intersection.Detector.Touched:Connect(Detect)
bindable.Event:Connect(Change)
prime crypt
bronze sun
#

No, when you call the function you need to pass in power and hit

#

Change(1, game.workspace.banana) would be an example of calling it

prime crypt
bronze sun
#

Change this
ToggleGUI(hit)
Change(hit)

To this
ToggleGUI(hit)
Change(Power, hit)

#

You need to pass in both

#

But make sure power is replaced with whatever you need it to be replaced with

prime crypt
bronze sun
#

Where are you calling it

#

Let me see

#

Oh using the bindable events

#

Let me see the other script

prime crypt
#
UIS = game:GetService("UserInputService")
Players = game:GetService("Players")
Player = Players.LocalPlayer
local bindable = workspace:WaitForChild("Intersection").Detector.power
local cooldown = false
local power = 0
while task.wait(0.02) do
    if UIS:IsKeyDown(Enum.KeyCode.Q) and (Player.Character.HumanoidRootPart.Position.Magnitude < Vector3.new(-78,4,66).Magnitude and Player.Character.HumanoidRootPart.Position.Magnitude > Vector3.new(-82,2,56).Magnitude) and power<100 then
        power = power+1
        bindable:Fire(power)
    end
    if power>=100 then
        task.wait(1)
        power = 0
    end
end
bronze sun
#

Yea, do bindable:Fire(power, hit)

#

You need to pass in hit

prime crypt
#

so its marked red

bronze sun
#

Well then why do you need hit in the function?

prime crypt
bronze sun
#

Yes but you have no hit anywhere

#

So there is nothing to pass in

#

If you need to make 2 separate functions one for if there is a hit and one for if there is not

prime crypt
bronze sun
#

Yea probably a good idea

#

Just modify it a bit

prime crypt
silk duneBOT
#

studio** You are now Level 6! **studio

bronze sun
#

Nice

#

Good luck on the future project