Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

script crashes game when executed?

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

5 comments

0

Are you sure the error is coming from this script and this part?

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

0

it is a problem with the debounce

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

0

thank u, i will try to fix the formatting and the debounce problem, but atleast now i know what the problem is

1 answer

✓ Accepted answer

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)

3 comments

0

what will that do?

0

thank you, i will test this right now

0

THANK U!!!! it worked perfectly

This discussion is preserved as it was. New answers, comments, and votes are closed.