These scripts work in Studio, not in game.
local trampoline = script.Parent trampoline.Velocity = Vector3.new(0,100,0) function onTouch(hit) wait(0.000001) if hit.Parent:FindFirstChild("Humanoid") then local i = 1 while i < 10 do hit.Parent:FindFirstChild("Humanoid").Jump = true wait(0.001) end end end script.Parent.Touched:connect(onTouch)
Line 1 and Line 2 make the trampoline bounce you. However if you do not hold down the jump button then the trampoline bounces you repeatedly about 5 studs into the air really fast (basically it breaks and glitches). Therefore I made a script that makes you jump and it makes the trampoline work beautifully, but the jump script only works in studio and not in game.
function onTouch(hit) wait(0.1) if hit.Parent:FindFirstChild("Humanoid") then hit.Parent.Torso.Velocity = Vector3.new(0,100,0) wait(0.1) end end script.Parent.Touched:connect(onTouch)
Alternatively this script above works and does not need the jump script and works fine in studio but is completely broken in game. I'm not so much looking for a method to fix this if there isn't one but a new method of making a Trampoline if mine are incorrect, sorry for being long winded I was just wanted to be clear and precise, any help is greatly appreciated.P.S. I've looked at many trampoline free models and they all are broken if not buggy to the least when I test them in game. Thank you.
I'm not completely sure why your method isn't working, so I just tried a different one using BodyVelocity It works fine in the studio and out of it.
script.Parent.Touched:connect(function(hit) wait(0.1) if hit.Parent:WaitForChild("Humanoid") then print("Work") local bv = Instance.new("BodyVelocity", hit.Parent.Torso) bv.maxForce = Vector3.new(math.huge,math.huge,math.huge) bv.velocity = Vector3.new(0,60,0) wait(0.01) bv:Remove() end end)
Basically, it checks for the player's humanoid then inserts a BodyVelocity which will make the player thrust upwards, then removes the BodyVelocity.
Hope this helped!
I figured it out: the reason it's not working is because that's a server script attempting to influence a Part that is owned by the client (your entire character's physics/animations are controlled by your Client, never the server), so the velocity proposed by the server is overwritten by the Client (and therefore ignored). (The reason this works in Play Solo mode is because in that mode, you are simultaneously the server and the client, so they cooperate better.)
To fix this, you need to tell the Client to make the change instead of making it from the server. Do that with this setup:
-- Trampoline part Script (put as a child to the trampoline part) function onTouch(hit) local p = game.Players:GetPlayerFromCharacter(hit.Parent) if p then game.ReplicatedStorage.Jump:FireClient(p) end end script.Parent.Touched:connect(onTouch) -- Put a RemoteEvent named "Jump" in game.ReplicatedStorage -- Put the following LocalScript in game.StarterPlayer.StarterCharacterScripts local p = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart") game.ReplicatedStorage.Jump.OnClientEvent:Connect(function() p.Velocity = Vector3.new(0, 100, 0) end)
Minor note: calling wait(0.01)
(or 0.00001) is pointless, as Roblox's minimum wait time is around 0.03 seconds. If you want to wait for that amount of time or less, simply call wait()
. Further, calling wait()
(regardless of what number you give it) is useless if you do it at the end of a function that is connected to an event (since the function can still run multiple times simultaneously due to being started in a coroutine), unless you use debounce.
Also note that you should never use Torso
, as R15 models don't have Torsos, see http://wiki.roblox.com/index.php?title=API:Class/Humanoid.