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

Trying to make a trampoline script. It works in studio but doesn't in game. Can I have some help?

Asked by
hozla 5
6 years ago
Edited 6 years ago

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.

2 answers

Log in to vote
0
Answered by 6 years ago

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!

1
Thank you for making this it works great although the problem is that the trampoline glitches your jump if you don't hold down spacebar to jump before you land and this is what I was trying to get rid of and it still occurs in this script. However I made a automatic jump script which makes you jump and removes this glitch although the jump script works in studio and breaks in game. Futhermore the xdeno 187 — 6y
1
2nd script in this question works like a charm in studio with no glitch what so ever but breaks in game. I appreciate the answer and the effort but it hasn't gotten us any further, what we really need is a fix for why the only work in Studio if you could because we are noobs xD. If your not sure don't stress it, I appreciate the help very much, thank you. xdeno 187 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.

0
You've over complicated this, I've gotten it to work fine thank you though. xdeno 187 — 6y
0
@Xdeno: if you've gotten it to work in a simpler fashion, why not let us know how you did it in an answer? chess123mate 5873 — 6y

Answer this question