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

How to get the CFrame from the Client ?

Asked by
farrizbb 465 Moderation Voter
7 years ago
Edited 7 years ago

Okay so basically i'm doing an Amaterasu script and it is for FE ,but when i get to the CFrame part it doesn't work

--local script
local deez = game.ReplicatedStorage.MyRemoteEvent
local Player = game.Players.LocalPlayer--find player
local Character = Player.Character
local debounce = true
local Mouse = Player:GetMouse()
function relay()
    local hit = Mouse.hit.p
    local userInputService = game:GetService("UserInputService")
    userInputService.InputBegan:connect(function(input, processed)
    if Character.Head.Texture == "http://www.roblox.com/asset/?id=108227137" then
        if input.KeyCode == Enum.KeyCode.Z then
            if debounce == true then
                debounce = false
                deez:FireServer("hit")
                wait(15)
                debounce = true
            end 
         end    
      end   
   end)         
end
--script
local deez = game.ReplicatedStorage.MyRemoteEvent

deez.OnServerEvent:connect(function(player, hit)
    local character = player.Character
    local z = Instance.new("Part")
                z.Parent = game.Workspace
                z.Name = "bb"
                z.CFrame = hit
                z.Transparency = 1
                z.Size = Vector3.new(5.81, 0.66, 7.65)
                local x = Instance.new("ParticleEmitter",game.Workspace.bb)
                x.VelocitySpread = 50
                x.Rate = 50
                local transparency = NumberSequence.new({NumberSequenceKeypoint.new(0,0.5,0),NumberSequenceKeypoint.new(1,0.5,0)})
                game.Workspace.bb.ParticleEmitter.Transparency = transparency
                x.Color = ColorSequence.new(Color3.new(0/0,0/0,0/0))
                x.Texture = "rbxgameasset://Images/b4d1cbee17f898243017bed18c835cff"
                x.Size =  NumberSequence.new(5)
                wait(5)
                z:remove()
                print(hit)

      end)

The error is at the line Z.CFrame = hit but i can't figure out how to fix it. This is the output

Workspace.Player1.Amaterasu:8: bad argument #3 to 'CFrame' (CFrame expected, got nil)

Thanks in Advance. Yours Sincerely far.

0
I agree with @AstreaDev . You are carrying over the string "hit" into the place of the parameter hit in your OnServerEvent. You can't get a CFrame from a string which is why it is printing nil. You can use the first parameter "player" for their CFrame or carry the players CFrame over. yougottols1 420 — 7y

3 answers

Log in to vote
2
Answered by 7 years ago

Your issue is that when you fire 'deez' you're passing "hit" which is a string type. In your server script for when 'deez' is fired you're doing:

z.CFrame = hit

hit is equal to that string you're passing that's "hit." Basically it's doing this:

z.CFrame = "hit"

A string is not a CFrame value. You need to do:

deez:FireServer(CFRAME_VALUE)

Read this to learn more about CFrames:

CFrame Wikipedia

Hope I helped :)

0
I still don't see why its wrong because hit is a CFrame Value is it a variable for Mouse.hit.p farrizbb 465 — 7y
0
Well, you see, in line 15 of the local script you're doing: deez:FireServer("hit"). If you want to pass the hit variable which is Mouse.hit.p you need to do: deez:FireServer(hit) AstrealDev 728 — 7y
Ad
Log in to vote
1
Answered by 7 years ago
Edited 7 years ago
Okay, so, I didn't really know what you wanted to do exactly with this script. But, I got bored and decided to fix a couple errors in your script.

Problem:

It seemed you were not connecting the function "relay" to any form ofevent or whatever. So I just used a tool's equipped event to solve this problem. You can change it back to how you like. You also didn't reference to the players "face" or the decal in the player's head which is what has the Texture--not the player's head alone. You also had something wrong with the uploading of your ParticleEmitter Texture Id. So, I just added a random one in there to substitute for it. Lastly, you had problems with the carrying over of the FireServer value so I just changed it from a string to mouse.Hit.p . In replace of the part's CFrame I just put it to the player's torso CFrame. You can change anything back how you like.

LocalScript:

local deez = script.Parent:WaitForChild("RemoteEvent")--Also changed the direction to get to the Remote event and renamed it.

local Player = game.Players.LocalPlayer--find player

local Character = Player.Character
local debounce = true
local Mouse = Player:GetMouse()
function relay()
    local hit = Mouse.hit.p
    local userInputService = game:GetService("UserInputService")
    userInputService.InputBegan:connect(function(input, processed)
    if Character:WaitForChild("Head"):WaitForChild("face").Texture == "http://www.roblox.com/asset/?id=20722053" then --It also errored here because you did not reference to the face. Which is in the head of the player and has the texture.
    --http://www.roblox.com/asset/?id=20722053(mine)
    --http://www.roblox.com/asset/?id=108227137(his)
        if input.KeyCode == Enum.KeyCode.Z then
            if debounce == true then
                debounce = false
                deez:FireServer(Mouse.Hit.p)--Changed it just in case you wanted the mouse.Hit.p, this way the "hit" parameter will take that value.
                wait(15)
                debounce = true
            end
         end   
      end  
   end)        
end

script.Parent.Equipped:connect(relay)--I connected the function to run the code. Change it back to whatever you used to connect the function. I just used a tool in this instance.

Script:

local deez = script.Parent:WaitForChild("RemoteEvent")--Also changed the direction to get to the Remote event and renamed it.



deez.OnServerEvent:connect(function(player, hit)
    local character = player.Character
    local z = Instance.new("Part")
                z.Parent = game.Workspace
                z.Name = "bb"
                z.CFrame = character.Torso.CFrame--Didn't know if you wanted it to be directly at the player or where they click.
                z.Transparency = 1
                 z.CanCollide = false --If you wanted it to somehow move to where you click then ignore lines 12-13 by deleting it.
                 z.Anchored = true
                z.Size = Vector3.new(5.81, 0.66, 7.65)
                local x = Instance.new("ParticleEmitter",game.Workspace.bb)
                x.VelocitySpread = 50
                x.Rate = 50
                local transparency = NumberSequence.new({NumberSequenceKeypoint.new(0,0.5,0),NumberSequenceKeypoint.new(1,0.5,0)})
                game.Workspace.bb.ParticleEmitter.Transparency = transparency
                x.Color = ColorSequence.new(Color3.new(0/0,0/0,0/0))
                x.Texture = "rbxasset://textures/particles/sparkles_main.dds" --Had to change the texture id because it would fail to load, change it to what you like
                x.Size =  NumberSequence.new(5)
                wait(5)
                z:remove()
                print(hit)

      end)
Note, just ignore the top portion for some reason when I made the answer it decided to add a comment about what I thought into a script and I can't change it.
Log in to vote
0
Answered by
farrizbb 465 Moderation Voter
7 years ago
Edited 7 years ago

I've taken both of your answers into consideration and this is what i have now .

--local script
local deez = game.ServerStorage.deez
local Player = game.Players.LocalPlayer--find player
local Character = Player.Character
local debounce = true
local Mouse = Player:GetMouse()
function relay()
    local hit = Mouse.hit.p
    local userInputService = game:GetService("UserInputService")
    userInputService.InputBegan:connect(function(input, processed)
    if Character.Head.face.Texture == "http://www.roblox.com/asset/?id=108227137" then
        if input.KeyCode == Enum.KeyCode.Z then
            if debounce == true then
                debounce = false
                deez:FireServer(hit)
                wait(15)
                debounce = true
            end    
         end    
      end    
   end)            
end               
--script
local deez = game.ServerStorage.deez

deez.OnServerEvent:connect(function(player, hit)
    local character = player.Character
    local z = Instance.new("Part")
                z.Parent = game.Workspace
                z.Name = "bb"
                z.CFrame = hit
                z.Transparency = 1
                z.Size = Vector3.new(5.81, 0.66, 7.65)
                local x = Instance.new("ParticleEmitter",game.Workspace.bb)
                  x.VelocitySpread = 50
                  x.Rate = 50
                  local transparency = NumberSequence.new({NumberSequenceKeypoint.new(0,0.5,0),NumberSequenceKeypoint.new(1,0.5,0)})
                  game.Workspace.bb.ParticleEmitter.Transparency = transparency
                 x.Color = ColorSequence.new(Color3.new(0/0,0/0,0/0))
                  x.Texture = "rbxgameasset://Images/b4d1cbee17f898243017bed18c835cff"
                  x.Size =  NumberSequence.new(5)
                wait(5)
                z:remove()
                print(hit)

      end)

Even with this it still wont work.

Answer this question