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

I don't understand why this doesn't work? I am kind of new to scripting

So I'm trying to make a script personally for me just for scripting practice. Then I realized this would make as a really good game. There aren't any errors in the output at all, and I have checked the wiki about 20 times. So please help.

local player = game.Players.LocalPlayer.Character
local UserInputService = game:GetService("UserInputService")


while wait(0.2) do
	function onInputBegan(inputObject, gameProcessedEvent)
   	 if inputObject.KeyCode == Enum.KeyCode.F then
       	 local ball = Instance.new("Part", workspace)
			ball.Parent = player.Torso
			ball.BrickColor = BrickColor.new("Teal")
			ball.Material = "Plastic"
			ball.Transparency = .6
			
			local Weld = Instance.new("Weld", ball)
			Weld.Part0 = ball
			Weld.Part1 = player.Torso
			ball.CFrame = player.Head.CFrame
			Weld.C0 = ball.CFrame:inverse()
			Weld.C1 = player.Torso.CFrame:inverse()
			ball.Anchored = false
			wait(1)
			ball:Destroy()
			Weld:Destroy()
end
end
end

UserInputService.InputBegan:connect(onInputBegan)

4 comments

0

you didn't call the function onKeyPress.

0

your supposed to call the function using an event. if you got this function from userinputservice then check the events for it and link it to onKeyPress

0

OMG I COMPLETELY FORGOT TO DO THAT!

0

Still didn't work. I changed the script so you can see what I changed it to, but I may have done something wrong

1 answer

You have the function in an infinite loop. Not only is this super inefficient, it will keep your code from working.

Why?

Line 28, where you connect the function to an event, never actually runs. The script stays in the while loop for eternity, and never reads that line.

Just get rid of the while loop and you'll be getting somewhere.

2 comments

0

So then what? Cause it still doesn't work :p

0

The event should be firing now. The rest of your code is correct as far as syntax is concerned, although you may want to mess around with stuff to get the effect you're looking for.

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