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

Torso position won't update?

Asked by 9 years ago

I have a script that drops a glowstick when your press the key "F". It works by cloning a glowstick from ReplicatedStorage, moves it to the players torso's position, and drops it there. And it works fine, however it seems that the torso's position doesn't update properly everytime you drop it. Specifically, it seems that when you press "F" to drop a glowstick, it drops it at the players last position, not its current one. I noticed this when i would drop a glowstick at one end of a hall. Then i walked to the other end and dropped another one, and the next one i dropped dropped at the opposite side of the hall from where i currently was (so it dropped in the same position as my first one). Then the next flare I dropped dropped in the right position (the characters current position). If my explanation is confusing you, basically whats happening is there's some lag between the characters last position, and the characters new position. Here's my script:

local uis = game:GetService("UserInputService")

uis.InputBegan:connect(function(inst)
    if inst.KeyCode == Enum.KeyCode.F then
        local flare = game.ReplicatedStorage:FindFirstChild("Flare")
        flare:Clone().Parent = game.Workspace
        local location = game.Workspace:FindFirstChild(game.Workspace.Player.Value)
        flare.CFrame = CFrame.new(location.Torso.Position)
    end
end)

NOTES: "Player.Value" is a string value located inside workspace who's value changes to the name of the player when the player joined. The reason I found the players name this way was because I couldn't figure out how to find the players name within this script. The players name script is an entirely different script located inside workspace.

flare = glowstick(Its a glowstick, but when I was coding, I called it flare because it was easier :P).

All help is appreciated!

0
try a loop? yoshi8080 445 — 9y
0
how? ZeMeNbUiLdEr 104 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

Try this:

local uis = game:GetService("UserInputService")

uis.InputBegan:connect(function(inst,GPE)
    if inst.KeyCode == Enum.KeyCode.F and not GPE then
        local flare = game.ReplicatedStorage:FindFirstChild("Flare")
        local fc = flare:Clone()
    fc.Parent = game.Workspace
        local location = game.Workspace:FindFirstChild(game.Workspace.Player.Value)
        fc.CFrame = CFrame.new(location.Torso.Position)
    end
end)

Explanation: The torso position is updating, but the correct flare is not being positioned. You are updating the position of the flare which is in ReplicatedStorage not the clone that is in Workspace.

Hope it helps :)

0
Ohhh...I knew I made a stupid mistake! Thanks! ZeMeNbUiLdEr 104 — 9y
Ad

Answer this question