I need some help with scripting!

I am making a football (soccer) game.

I want to make a function where you can hold down left mouse button or for people with touchscreen without a mouse, it will run if they hold their finger on the screen.

There will be a value in the player’s character called “ShootPower”, which will be set to 20 automatically, the default dribbling power.

I can create everything, except the script for increasing power when someone holds the screen or mouse.

Help would be really appreciated!

1 Like

Not to sound mean or anything but:

  • The rules for the scripting support forum are to not to ask for entire scripts, just for help with scripts you’ve tried and aren’t working.

  • They also ask if you’ve looked at other sources for the information, such as the Search window up top, Google, or the create.roblox.com site.

  • You also put ‘bug’ in your keywords, but this isn’t a bug report. Please use keywords that actually describe the issue.

1 Like

I don’t know why I would call this mean, it’s just advice.

I’m not asking for an entire script, the only thing I need from people viewing, is to show me how to check if a player is holding their mouse or holding the touch screen.

I don’t know how to do this, that’s why I asked the forum.
I could ask ChapGPT, but I actually want to learn how to do it, as I am just a biginner scripter making my own game.

1 Like

you can use os.clock() for this. to simplify os.clock, it is the amount of cpu used by lua in seconds. we can just think of os.clock() as time. so, we want to get the time between when you press the input and the time when you end the input. that will look like

-- example
local starttime = os.clock() -- time when player first touches screen
inputendedevent:Connect(function()
   local timedifference = os.clock() - starttime -- os.clock currently in this event is the time when we end the inputendedevent because it's just constantly counting in seconds outside of our vision.
end)

now we can just use timedifference as the power multiplied by whatever you want if the power isn’t enough

edit: ask questions if you’re confused on anything :smile:

I think this should work. I also just made a little script that turns a value inside the player character true whenever the screen is being held down.

If i’m not asking for too much, could you tell me how to add 1 to a value every let’s say 1 second

you can use a while loop if you want it to be indefinite until a condition.
heres a script example:

while task.wait(1) do
   value += 1
end

Such an easy script but never thought of that!

Thank you

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.