Thank you for reading this.
So, for my platformer game, i want to make a flagpole at the end something like super mario bros. I have this custom control script and a serverscript.
(Also the purpose of the controlOn variable is for the cutscene to happen without the player moving)
This is the error that pops up:
20:19:13.540 - Players.hasanchik.PlayerScripts.ControlScript:46: attempt to index boolean with 'Name' 20:19:13.540 - Stack Begin 20:19:13.541 - Script 'Players.hasanchik.PlayerScripts.ControlScript', Line 46 20:19:13.541 - Stack End
Server script:
local ts = game:GetService("TweenService") local rs = game:GetService("ReplicatedStorage") local remote1 = rs:WaitForChild("PlayerControl") local debris = game:GetService("Debris") local db = false local bottom = script.Parent.Flagpole.Bottom local top = script.Parent.Flagpole.Top local flag = script.Parent.Flagpole.Flag local pole = script.Parent.Flagpole.Pole function guiBegin(player) local guiCoroutine = coroutine.create(function() local gui = script.FadeOut:Clone() local frame = gui:FindFirstChild("FadeOutFrame") gui.Parent = player.PlayerGui local goal = {BackgroundTransparency = 0} local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0) local fadeIn = ts:Create(frame, tweenInfo, goal) fadeIn:Play() wait(2.1) local goal = {BackgroundTransparency = 1} local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0) local fadeOut = ts:Create(frame, tweenInfo, goal) fadeOut:Play() wait(1) debris:AddItem(gui, 0.1) end) coroutine.resume(guiCoroutine) end pole.Touched:Connect(function(part) local HRP = part.Parent:FindFirstChild("HumanoidRootPart") local player = game.Players:GetPlayerFromCharacter(part.Parent) if HRP and player and not db then db = true HRP.Anchored = true local goal = {Position = Vector3.new(HRP.Position.X,bottom.Position,HRP.Position.Z)+Vector3.new(0,3,0)} local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0) local Glide = ts:Create(HRP, tweenInfo, goal) Glide:Play() bottom.LevelComplete:Play() wait(1) HRP.Anchored = false db = false remote1:FireClient(player, false) end end)
Client script:
local player = game.Players.LocalPlayer local RunService = game:GetService("RunService") local ContextActionService = game:GetService("ContextActionService") local rs = game:GetService("ReplicatedStorage") local remote1 = rs:WaitForChild("PlayerControl") local controlOn = true local jumping = false local leftValue, rightValue = 0, 0 local function onLeft(actionName, inputState) if inputState == Enum.UserInputState.Begin then leftValue = 1 elseif inputState == Enum.UserInputState.End then leftValue = 0 end end local function onRight(actionName, inputState) if inputState == Enum.UserInputState.Begin then rightValue = 1 elseif inputState == Enum.UserInputState.End then rightValue = 0 end end local function onJump(actionName, inputState) if inputState == Enum.UserInputState.Begin then jumping = true elseif inputState == Enum.UserInputState.End then jumping = false end end local function onUpdate() if player.Character and player.Character:FindFirstChild("Humanoid") and controlOn then if jumping then player.Character.Humanoid.Jump = true end local moveDirection = rightValue - leftValue player.Character.Humanoid:Move(Vector3.new(moveDirection,0,0), false) end end remote1.OnClientEvent:Connect(function(player2, controlOn2) if player2.Name == player.Name then controlOn = controlOn2 end end) RunService:BindToRenderStep("Control", Enum.RenderPriority.Input.Value, onUpdate) ContextActionService:BindAction("Left", onLeft, true, "a", Enum.KeyCode.Left, Enum.KeyCode.DPadLeft) ContextActionService:BindAction("Right", onRight, true, "d", Enum.KeyCode.Right, Enum.KeyCode.DPadRight) ContextActionService:BindAction("Jump", onJump, true, "w", Enum.KeyCode.Space, Enum.KeyCode.Up, Enum.KeyCode.DPadUp, Enum.KeyCode.ButtonA)
Can you help me? Thanks.
So basically the problem here I think is that your the false argument that u put in the :FireClient event is set as the player2 value in your clientscript. The "Player" argument in your FireClient part is being not sent to the client script resulting into the false argument being the first parameter in your OnClientEvent part. So basically the script is thinking that your first parameter is the boolean false.
My suggestion is that you do this
remote1:FireClient(player,player.Name,false)
then I think its supposed to work.
If this did'nt work then I am will try to look more into it
Either player2 or player is a boolean value(True/False)
Let me take a deeper look into your code and ill edit this when I find the line that the boolean is created.
Happy scripting, Tim
On line 43 of the Script
you have:
remote1:FireClient(player, false)
On line 45 of the LocalScript
you have:
remote1.OnClientEvent:Connect(function(player2, controlOn2)
On line 46 of the LocalScript
you have:
if player2.Name == player.Name then
Since the first argument to an event is always "Player", the second argument (which is false
) would be "player2" and "controlOn2" wouldn't even exist.
This can be fixed easily by replacing line 45 to 49 with
remote1.OnClientEvent:Connect(function(controlOn2) controlOn = controlOn2 end)