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

StarterCharacter CFrame won't work?

Asked by 1 year ago

So it's a Normal script, not a local or anything It is parented inside the starter character why won't it work? It's also not showing any error in the console... Code:

Click=game.Players.LocalPlayer:GetMouse().Button1Down:Connect(function()
    for i, v in pairs(script.Parent:GetChildren()) do
        if v:FindFirstChild("Right Arm").rarm and v:FindFirstChild("Left Arm").larm then
            v.Position = CFrame.new(96.354, 9.749, -190.868) and v.Position == CFrame.new(88.072, 9.749, -190.868)
        end
    end
end)

Click2=game.Players.LocalPlayer:GetMouse().Button1Up:Connect(function()
    for i, v in pairs(script.Parent:GetChildren()) do
        if v:FindFirstChild("Right Arm").rarm and v:FindFirstChild("Left Arm").larm then
            v.Position = CFrame.new(96.354, 8.833, -182.557) and v.Position == CFrame.new(88.072, 8.833, -182.557)
        end
    end
end)

1 answer

Log in to vote
0
Answered by 1 year ago

I tested out your script and I got a few errors. I believe they're because some things can only be done on LocalScripts. The issues I got were with LocalPlayer and GetMouse() as those can only be done on LocalScripts. GetMouse() can be used in normal scripts by using remote events (it looks like LocalPlayer is used to call GetMouse()) to change the CFrame on the server's side. With your problem, you are trying to see if the child in script.Parent:GetChildren() is BOTH the right arm and left arm when you put "and" in the if statement. You are also trying to find the child of the player's model's children, so the right arm and left arm wouldn't be in there (you would need to check the part's name, not the part's child), unless you changed the player's model (if so, it should be fine). There will also be a problem between R6 and R16; unless you set everyone's body type to R6, you woudn't see RightArm or LeftArm in R16 because they are all different parts (RightUpperArm, RightLowerArm, RightHand, LeftUpperArm, LeftLowerArm, LeftHand) I would do this (My changes to your script):

--This is the script in StarterCharacterScripts
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--Create 2 RemoteEvents in ReplicatedStorage (This is accessible by both the server and client). Name one Button1Down and the other Button1Up.
local Button1DownRemoteEvent = ReplicatedStorage:WaitForChild("Button1Down")--The WaitForChild() ensures the RemoteEvent loads in before your script tries to call it.
local Button1UpRemoteEvent = ReplicatedStorage:WaitForChild("Button1Up")--You can name these 2 locals to be whatever you want.

Button1DownRemoteEvent.OnServerEvent:Connect(function()
    for i, v in pairs(script.Parent:GetChildren()) do
        if v.name == "RightArm" or v.name == "RightUpperArm" then--You can change the second one to RightLowerArm or RightHand. v.name == "RightArm" checks R6 bodies and v.name == "RightUpperArm" checks R15, so delete the other if you set all player's models to be R6 or R15. (This goes for all the If and ElseIf statements in this script)
            v.CFrame = CFrame.new(96.354, 9.749, -190.868)--Change the CFrames to be whatever you want. (This goes for all the other CFrames)
        elseif v.name == "LeftArm" or v.name == "LeftUpperArm" then
            v.CFrame = CFrame.new(88.072, 9.749, -190.868)
        end
    end
end)

Button1UpRemoteEvent.OnServerEvent:Connect(function()
    for i, v in pairs(script.Parent:GetChildren()) do
        if v.name == "RightArm" or v.name == "RightUpperArm" then
            v.CFrame = CFrame.new(96.354, 8.833, -182.557)--change this to be whatever u want
        elseif v.name == "LeftArm" or v.name == "LeftUpperArm" then
            v.CFrame = CFrame.new(88.072, 8.833, -182.557)--change this to be whatever u want
        end
    end
end)

LocalScript:

--This is a LocalScript in StarterPlayerScripts:
local players = game:GetService("Players")
local plr = players.LocalPlayer
local mouse = plr:GetMouse()

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Button1DownRemoteEvent = ReplicatedStorage:WaitForChild("Button1Down")-- you can change these 2 locals to be whatever you want
local Button1UpRemoteEvent = ReplicatedStorage:WaitForChild("Button1Up")-- you can change these 2 locals to be whatever you want

mouse.Button1Down:Connect(function()
    Button1DownRemoteEvent:FireServer()
end)
mouse.Button1Up:Connect(function()
    Button1UpRemoteEvent:FireServer()
end)

Now, this worked for me, however, it doesn't seem to do what I think you want. If you're trying to move their arms, then I would do an animation rather than changing their CFrames. If you need help on that, I can help you to the best of my ability, yet I can only help so much through this site. You will definitely need to do some research on your own on how animations work, but I'm here to help! (I have experience with animations)

Ad

Answer this question