So in my Spider-Man game I’m making a zip to point system. How it works is once the player points their mouse at something and press R, it fires a remote event to the server and creates a new part. Then it tweens the characters HumanoidRootPart to that part. So basically a grapple hook in a way.
I’m trying to add to it once the player gets to the point they can press space and get a boost off the zip. I’ve tried using tick() but that hasn’t seemed to work. Help?
If you have for example 5 seconds tweening time, you could use wait() and put the tweening time inside, so next command would be executed right after the tweening ends.
This is what I mean. After the tween is completed, they have like 0.1 seconds after to press space to boost themselves off the zip. If they don’t press it in time, nothing happens.
To Detect if a player has clicked in a certain time space i would recommend adding debounce for the duration and using
Mouse.Button1Up:Wait(1)
This will wait untill the button has been released but the limit of time you can also give to the :Wait() as a parameter
Then to check if the player has clicked in the waiting time, make a variable and check if its true.
Okay, I don’t think its the simplest idea, but it works. Here’s the code. I used bindable event to make this.
Local player script
local userInputService = game:GetService("UserInputService")
local zipTime = 5 --make this number of seconds the zip takes
local boostTime = 0.5 --make this
local cooldown = false
local boost = false
userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.R then
if cooldown == false then
cooldown = true
print("zipping") --Make your tween here, with lenght of zipTime
wait(zipTime)
script.Event:Fire()
cooldown = false
end
end
end
end)
userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.Space then
if boost == true then
print("boosted") --your boost code goes here
end
end
end
end)
script.Event.Event:Connect(function()
boost = true
wait(boostTime)
boost = false
end)