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

A script that's seemingly perfectly fine doesn't execute a line?

Asked by 5 years ago

Apparently, some line of code isn't giving an error, but It's not doing what it's supposed to do. This script is a local script in starter player scripts.

local UserInputService = game:GetService("UserInputService")
local LocalPlayer = game.Players.LocalPlayer
local waiting = false
local function CharacterAdded(char)
    Character = char
    Humanoid = char:WaitForChild("Humanoid")
end

if LocalPlayer.Character then
    CharacterAdded(LocalPlayer.Character)
end

LocalPlayer.CharacterAdded:connect(CharacterAdded)
UserInputService.JumpRequest:connect(function()
    if not Character or not Humanoid or not Character:IsDescendantOf(workspace) or Humanoid:GetState() == Enum.HumanoidStateType.Dead then
        return
    end
    if LocalPlayer.Box.Value == 0 then
        return
    end
    if not waiting then
        waiting = true
        LocalPlayer.Box.Value = 0
        local torso = Character:FindFirstChild("Torso")
        if torso then
            torso.Velocity = Vector3.new(torso.Velocity.X, Humanoid.JumpPower*0.9, torso.Velocity.Z)
        end
        wait(0.25)
        waiting = false
    end
end)

And this script here is a script inside a part.

local str = ""
local obj
script.Parent.MouseClick:Connect(function(hit)
    obj = hit
    str = hit.Name.."a"
    hit.Character.Torso.CFrame = (script.Parent.Parent.CFrame * CFrame.Angles(0,math.pi,0)) - Vector3.new(0,2.5,0)
    script.Parent.Parent.WeldConstraint.Part1 = hit.Character.Torso
    script.Parent.Parent.Anchored = false
    script.Parent.MaxActivationDistance = 0
    hit.Box.Value = 1
end)
script.Parent.Parent.Touched:Connect(function(hit)
    if hit.Name == "fail" then
        script.Parent.Parent.WeldConstraint.Part1 = nil
        obj.Box.Value = 0
    end 
    if script.Parent.Parent.WeldConstraint.Part1.Name == "Torso" then
        print("success")
        --This is where the error is, When the other event triggers, It sets the value to 0, but this doesnt set it to 1 again.
        --The success line does print.
        obj.Box.Value = 1
    end
end)
0
Please check the 2nd script entirely. mlgwinners 30 — 5y
0
Do you know where it stops running? If not, for your own convenience, print something each time something successfully happens so you can get a better understanding of where it stops. That will make it much easier to debug. vanilla_wizard 336 — 5y
0
ok i might mlgwinners 30 — 5y

Answer this question