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

My Jumpscare scripts Work in ROBLOX Studio, but not in the ROBLOX game Engine!?

Asked by
squ1b 5
6 years ago

I have tried to fix this by myself over the course of two days now, and it has never seemed to work. I'm just going to leave the exact code I'm using and ask what is wrong with it, then I'll be on my merry way. Here is a brief overview of what I'm doing. The game chooses a number from one to eight. The number chosen determines which "He" is going to be visible. "He" is a hunched over black figure with a non - closing jaw. "He" is a union, and in a group with a part I named "HitBox", which extends a great distance if front of "Him". I named each model "HIM1(HIM2, + etc, until HIM8)" Whenever a "Him" is visible, the script inside the "HitBox" from that model is enabled. This is the script:

plr = game.Players.LocalPlayer
canAttack = true

script.Parent.Touched:connect(function(part)
    local h = part.Parent:FindFirstChild("Humanoid")
    if h ~= nil then
        if canAttack == true then
            canAttack = false
            game.Players.LocalPlayer.Character.Humanoid.Health = 0
            workspace.Randomizer.Sound:Play()
            print("Jumpscare Activated")
            game.Players.LocalPlayer.JumpScare.Value = true
            wait(7)
            canAttack = true
        end
    end
end)

Next, I put a LocalScript into the StarterGui, titled "JumpscareScript".

plr = game.Players.LocalPlayer
local jumpscare = Instance.new("BoolValue")
jumpscare.Value = false
jumpscare.Name = "JumpScare"
jumpscare.Parent = plr
cam = workspace.CurrentCamera

function Jumpscare()
    plr.JumpScare.Value = false
    wait(2)
    plr.Character.Humanoid.Health = 0
    cam.CameraType = "Scriptable"
    cam. CFrame = workspace.JumpScareCam. CFrame
    workspace.JumpScareCam.Sound.Playing = true
    wait(2)
    game.Lighting.Dark.Enabled = true -- This causes the screen to go dark.
    cam.CameraType = "Custom"
    cam.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
    workspace.PurpleDoor.CanCollide = true --Ignore this. These are just doors that
    workspace.PurpleDoor.Transparency = 0  --could have been opened by the player,
    workspace.Exit.CanCollide = true       --so that on their deaths the doors close
    workspace.Exit.Transparency = 0        --again.
    workspace.RedDoor.CanCollide = true    --|
    workspace.RedDoor.Transparency = 0     --|
    workspace.BlueDoor.CanCollide = true   --|
    workspace.BlueDoor.Transparency = 0    --`
end

workspace.Randomizer.Sound.Played:connect(Jumpscare)

The "Sound" played when the "HitBox" is touched in the first script has a greater purpose, as when it is played, according to the LocalScript, it causes the function to activate. In the studio, the result is the camera being shoved right up into "His" face and an equally terrifying screeching noise (and the player's death, of course) ; however, online, the result is nothing. I would just like to know what I did wrong, how to fix it, and why it is the solution. This is literally the LAST thing I need to do before the game is released, and this is my first project. This is the first installment of a series called "Meta Minigames", in which the struggles of my friends in real life are twisted and put into horror game form. This one is called "Kalissa's Minigame", and it covers abuse, and it contains a bit of lore for a game series I will be working on after I complete this one. This next series will benefit greatly from this, too. Thank you! :P

0
must be in localscript in startergui, otherwise game.players.localplayer doesn't work greatneil80 2647 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Is the first code in a local script? You cannot access the local player in a server script of course.

If the first code is a local script, is it a descendant of a player during runtime? Descendant means it's either a child, grandchild, great grand child, great great grandchild ( and so on... ). In otherwords, local scripts should be placed in playerstarter scripts or playergui to function, but your code suggests that it's a child of a "Him" that descends from workspace.

In roblox studio the server and client is one and the same, so you can get away with being ignorant of server client distinctions. In live server, the server and client are seperated, so any mistakes you make will show. You can press f9 -> client / server log to look for errors online. I suggest you get more familiar with client server distinctions in general.

Ad

Answer this question