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

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

Asked by 8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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)

0
you didn't call the function onKeyPress. KordGamer 155 — 8y
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 LifeInDevelopment 364 — 8y
0
OMG I COMPLETELY FORGOT TO DO THAT! RetroThieff 5 — 8y
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 RetroThieff 5 — 8y

1 answer

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
8 years ago

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.

0
So then what? Cause it still doesn't work :p RetroThieff 5 — 8y
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. Perci1 4988 — 8y
Ad

Answer this question