Im trying to make a camping game with tent but when I try to make tent it gives this error (on title), how can I fix it?
LocalScript code: --By enes223
local plr = game:GetService("Players").LocalPlayer local char = plr.Character or plr.CharacterAdded:wait() local torso = char:WaitForChild("Torso") local RS = game:GetService("ReplicatedStorage") local Remote = RS:WaitForChild("BuildTent") local Remote2 = RS:WaitForChild("BuildMegaTent") script.Parent.MouseButton1Click:Connect(function() if plr.Values.TentLevel.Value == 1 or 2 then local position = torso.Position script.Parent.Visible = false Remote:FireServer(position) elseif plr.Values.TentLevel.Value == 3 then local position = torso.CFrame.lookVector + Vector3.new(0,0,10) * 0 Remote2:FireServer(position) end end)
ServerScript code:
BuildTent.OnServerEvent:connect(function(plr,position) local tent = SS:WaitForChild("Tent") local clone = tent:Clone() clone.Parent = game.Workspace clone.Name = plr.Name.."'s Tent" clone.TentMesh.CFrame = position clone.TentMesh1.CFrame = position end)
You cannot set a CFrame
to a Vector3
value, as you do in your server script. Instead, you need to set the CFrame values of "TentMesh" and "TentMesh1" to the torso's CFrame, not it's position. To fix your error, just change the parameter you pass to the remote event to the torso's CFrame instead of it's position:
Remote:FireServer(torso.CFrame)
Another catch:
Your logic on the if
statement in your local script is incorrect. You have:
if plr.Values.TentLevel.Value == 1 or 2 then
Whereas you should have:
if plr.Values.TentLevel.Value == 1 or plr.Values..TentLevel.Value == 2 then
The individual statements that create a compound if
statement should be able to stand alone as separate if
statements. In your example, if they were separated (in terms of English) into separate if
statements, it would essentially look like this:
"if value == 1 or if 2 then ..."
That doesn't make any sense. The computer will interpret the second statement as, "if 2 is not nil then" which is definitely not what you want, because it's always true, therefore making your compound statement always true.
If you do my corrected version, it now properly looks like this:
"if value == 1 or if value == 2 then ..."