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

Script working and dying connected?

Asked by 5 years ago

I have a script that when I pull out the tool, it is supposed to constantly teleport a part to right beneath me, so I can sort of walk around on air.

it works fine in singleplayer, but when I test it with more than one person, it only works for the person that died last. I'm a bit confused about how my character dying and the hammer working are tied together. Please help. (It is not something outside this code, I have taken the model out of the place I am working on, and it works the same.)

local part
local cPlayer
local hammer = script.Parent
local pos
local cClayer
function OnCharJoin(character)  
    repeat wait() until character   
    --game.StarterGui.ScreenGui.TextButton.Value.Value = character
    cClayer = character
    print("char added")

    ini()
end
print("hello tsst 3")


function playerJoin(player)
    cPlayer = player
    player.CharacterAdded:connect(OnCharJoin)
    part = Instance.new("Part")
    part.Anchored = true
    part.Size = Vector3.new(11, 2, 11)
    part.Parent = workspace
    part.Position = Vector3.new(0, 10, 0)
    print("plr joined")
end

game.Players.PlayerAdded:Connect(playerJoin)

function ini()
    print("plr intietated")
    while true do
        wait(0.1)
        if cClayer:FindFirstChild("Scaffold Hammer") then
        pos = cClayer.HumanoidRootPart.Position


        part.Parent = workspace
        part.Position = cClayer.HumanoidRootPart.Position + Vector3.new(0, -4, 0)


        end
    end
end

1 answer

Log in to vote
0
Answered by 5 years ago

What I believe the error is from is because ini() is defined AFTER OnCharJoin, so the server gets confused and then cannot define it until the person has died. I don't know why dying and your script are connected, but I recommend you try making the ini() function get defined before OnCharJoin.

Ad

Answer this question