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

Why won't this script work? I have tried multiple methods to fix it. [ANSWERED]

Asked by 4 years ago
Edited 4 years ago

Hello, I am trying to achieve a Carry System but whenever a player comes

Here is the full code:

local UI = script.Parent
local RS = game:GetService("RunService")
local debugmode = 0
local firstply = "nil"
if debugmode == 0 then

RS.Stepped:Connect(function()
    local ply = game.Players:GetPlayers()
    for i,v in pairs(ply) do
       if game.Players.LocalPlayer:DistanceFromCharacter(v.Character.UpperTorso.Position) <= 10 and v.Name ~= game.Players.LocalPlayer.Name and firstply ~= v.Name then
            firstply = v.Name
            print(game.Players.LocalPlayer.Name.." is close to "..firstply..".")
            script.Parent.Visible = true
            script.Parent.PlayerCarried.Text = ("Carry, "..firstply.."?")
        else if game.Players.LocalPlayer:DistanceFromCharacter(v.Character.UpperTorso.Position) >= 10 and v.Name ~= game.Players.LocalPlayer.Name and firstply == v.Name then
            firstply = "nil"
            print(game.Players.LocalPlayer.Name.." is not close to "..firstply..".")
            script.Parent.Visible = false
            end
        end
    end
end)

elseif debugmode == 0 then

RS.Stepped:Connect(function()
        if game.Players.LocalPlayer:DistanceFromCharacter(game.Workspace.PlayerCarry.UpperTorso.Position) <= 10 then
            script.Parent.Visible = true
        else
            script.Parent.Visible = false
        end
    end)
end

UI.Carry.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.CarryEvent:FireServer(firstply, game.Players.LocalPlayer.Name)
    print(firstply)
end)

UI.Cancel.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.DropEvent:FireServer(firstply, game.Players.LocalPlayer.Name)
    print(firstply)
end)

The code that is erroring is:

game.Players.LocalPlayer:DistanceFromCharacter(v.Character.UpperTorso.Position) <= 10 and v.Name ~= game.Players.LocalPlayer.Name and firstply ~= v.Name then

This is the errors I receive: https://i.imgur.com/peJUGUU.png https://i.imgur.com/vefPWWJ.png

This is the output it gives: https://i.imgur.com/beCK31M.png https://i.imgur.com/tuSAn8f.png

Sorry, if the Images are blurred.

0
do u use r6? HappyTimIsHim 652 — 4y
0
I'm using R15. iiMxtt_Destinyii 62 — 4y
1
why is firstply a string? if you want to assign it's really nil, you should remove the quotation marks. also, pretty sure what's wrong is the "(v.Character.UpperTorso.Position) <= 10", because you haven't specified the axis (x,y,z) Goomiin 1 — 4y
0
Alright, that seemed to fix it. Thanks for the help. iiMxtt_Destinyii 62 — 4y
0
If it is fixed, you should put [Answered] in the question title so people know. CoolOlivie057 45 — 4y

Answer this question