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

script crashes game when executed?

Asked by 5 years ago
Edited 5 years ago

this script is for making a gui appear, music play, and camera change when you touch a part. that part works, but i think it works too many times as when you touch the part, it appears for a second, then crashes the game/studio..

i think the problem is the debounce, and it is not working correctly. i get no errors from this script either, but any help is really appreciated.

debounce = false  
function onTouched(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player and debounce == false then
        debounce = true
        player:WaitForChild("PlayerGui").Credits.Frame.Visible = true
    end


local Camera = game.workspace.CurrentCamera
workspace.ramp.Touched:Connect(onTouched)

Camera.CameraType = "Scriptable"
Camera.CFrame = game.workspace.CamPart2.CFrame

end

local debounce = false
Music = script.credits
STAR = game.SoundService.STAR
workspace.ramp.Touched:connect(function(hit)
if not hit.Parent:FindFirstChild("Humanoid") then return end
debounce = true
Music:Play()
STAR:Pause()
workspace.ramp.Touched:Connect(onTouched)
debounce = true
    game.Workspace.ramp.CanCollide = false
    game.Workspace.mainwall.CanCollide = true
end)

EDIT: Shortened my plea for help

0
Are you sure the error is coming from this script and this part? Pojoto 329 — 5y
0
i am pretty sure, this is the only script i've been working on, and the game only crashes when you touch the part which the script is referencing but i can't check for errors as the game crashes bowsercow 20 — 5y
0
it is a problem with the debounce thebayou 441 — 5y
0
also i can't really fix your problem because your code is just formatted so weird i have no clue which part belongs under where thebayou 441 — 5y
0
thank u, i will try to fix the formatting and the debounce problem, but atleast now i know what the problem is bowsercow 20 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Simply put a wait()

debounce = false  
wait()
function onTouched(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player and debounce == false then
        debounce = true
        player:WaitForChild("PlayerGui").Credits.Frame.Visible = true
    end

wait()
local Camera = game.workspace.CurrentCamera
workspace.ramp.Touched:Connect(onTouched)

Camera.CameraType = "Scriptable"
Camera.CFrame = game.workspace.CamPart2.CFrame

end
wait()
local debounce = false
Music = script.credits
STAR = game.SoundService.STAR
workspace.ramp.Touched:connect(function(hit)
if not hit.Parent:FindFirstChild("Humanoid") then return end
debounce = true
Music:Play()
STAR:Pause()
workspace.ramp.Touched:Connect(onTouched)
debounce = true
    game.Workspace.ramp.CanCollide = false
    game.Workspace.mainwall.CanCollide = true
end)
0
what will that do? thebayou 441 — 5y
0
thank you, i will test this right now bowsercow 20 — 5y
0
THANK U!!!! it worked perfectly bowsercow 20 — 5y
Ad

Answer this question