Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Trying to pass variables between functions with no luck? I accept answers!

So I'm trying to pass the variable player down to the code below the giveWeapon function. I'm not having any luck and the tutorials I have watched are not helping me much either and how would I go about passing the hit parameter down from the giveWeapon function to the function below as well?

local playersPlaneHitBox = game.ReplicatedStorage.planeHitBox
local rockets = game.ReplicatedStorage.PlaneRocket
local debounce = true
local sitCheck = false

local function giveWeapon(hit)
	local player = hit.Parent:FindFirstChild("Humanoid") ---Need to pass this variable down
	if player then
		if player.Sit == true then
			if not hit.Parent:FindFirstChild("PlaneRocket")then
				local clonedRocket = rockets:Clone()
				clonedRocket.Parent = hit.Parent
				print("test")
				sitCheck = true
			end
		end
	end
	return player
end
script.Parent.Touched:Connect(giveWeapon)

if player.Sit == false then ---I want to pass the player variable here
		if sitCheck == true then
		local clonePlaneHitBox = playersPlaneHitBox:Clone() ---I also want to pass the hit parameter here
		clonePlaneHitBox.Parent = game.Workspace
		clonePlaneHitBox.CFrame = hit.Parent.HumanoidRootPart.CFrame
	end
end
player()

3 comments

0

to where are you passing it?

1

what line you passing it to?

0

22

1 answer

I don't really understand what you want or what your doing with your script but this should do what you asked for.

local rs = game:GetService("ReplicatedStorage")
local phb = rs.planeHitBox
local pr = rs.PlaneRocket
local debounce = true
local sc = false

local plr
local plrhit

local function giveWeapon(hit)
	local player = hit.Parent:FindFirstChild("Humanoid")
	if player then
		if player.Sit then
			if not hit.Parent:FindFirstChild("PlaneRocket")then
				local clonedRocket = pr:Clone()
				clonedRocket.Parent = hit.Parent
				print("test")
				sc = true
			end
		end
	end
	plr = player
	plrhit = hit
end

if plr.Sit == false then
	if sc == true then
		local clonePlaneHitBox = phb:Clone()
		clonePlaneHitBox.Parent = game.Workspace
		clonePlaneHitBox.CFrame = plrhit.Parent.HumanoidRootPart.CFrame
	end
end

script.Parent.Touched:Connect(giveWeapon)

1 comment

0

It didn't really answer my question but I have since figured out how to pass variables.

This discussion is preserved as it was. New answers, comments, and votes are closed.