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

Client script remoteevent problem?

Asked by 4 years ago

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.

0
See the comment on my answer User#30567 0 — 4y

3 answers

Log in to vote
1
Answered by 4 years ago

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

0
still, why cant the script set the variable controlOn hasanchik 49 — 4y
0
i mean the if statement doesent work hasanchik 49 — 4y
0
on line 46 in the client script hasanchik 49 — 4y
0
That would return "Players.hasanchik.PlayerScripts.ControlScript:46: attempt to index string with 'Name'" User#30567 0 — 4y
View all comments (3 more)
0
no both player2.Name and player.Name return hasanchik (my name) do the if statement would have to work hasanchik 49 — 4y
0
Because you sent player.Name as the argument remember? So instead of doing player2.Name == player.Name you can just do player2 == player.Name. Hopefully this works DeUltimate23 142 — 4y
0
wait what the nani User#30567 0 — 4y
Ad
Log in to vote
1
Answered by 4 years ago

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

0
player is the localplayer, and player2 is the 31 line of code and then the player2 is fired at the 43 line in a serverscript hasanchik 49 — 4y
0
Got it. ThatDevTim 188 — 4y
0
There must be a problem with the 43 line of code in the serverscript, but the boolean is after the player. the boolean that is fired from the serverscript is in the client script controlOn2 which is on the second place in OnClientEvent:Connect(). controlOn2 is supposed to be a boolean, the first parameter is supposed to be a player object. I have no idea how this would error. hasanchik 49 — 4y
0
Have you tried using a print(Player2) and a print(Player) right before line 46? MIght be able to figure out the issue from that. ThatDevTim 188 — 4y
View all comments (19 more)
0
i tried printing, but it just printed hasanchik 49 — 4y
0
false (for player2 somehow) and nil for controlOn2 hasanchik 49 — 4y
0
Ok, we found our issue ThatDevTim 188 — 4y
0
player2 is the boolean value ThatDevTim 188 — 4y
0
The Server script is parsing player2 as false ThatDevTim 188 — 4y
0
What how hasanchik 49 — 4y
0
Ok DeUltimate23 answered the question but the if statement does not wotk hasanchik 49 — 4y
0
work hasanchik 49 — 4y
0
ITS DRIVING ME CRAZY hasanchik 49 — 4y
0
This should be in a comment. You literally translated the error message to english. THAT'S IT User#30567 0 — 4y
0
what do you mean by that hasanchik 49 — 4y
0
Try to remove the if statement I think it seems unecessary DeUltimate23 142 — 4y
0
No, Its for the checking for a specific player. If the statement wasnt there, everbody would freeze for like 5 seconds hasanchik 49 — 4y
0
nevermind hasanchik 49 — 4y
0
Have you tried using a print after the if statement to check if it gets past? DeUltimate23 142 — 4y
0
i figured out something, you didnt need the if statement because the fireclient line of code in the serverscript, the first parameter was the player to which the signal the script it sensed to hasanchik 49 — 4y
0
why couldnt you say that to me hasanchik 49 — 4y
0
i like kinda did, but glad to hear that it worked out :) DeUltimate23 142 — 4y
0
ok i admit i was dumb here hasanchik 49 — 4y
Log in to vote
1
Answered by 4 years ago

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)
0
BUT i have to do the CHECK to make sure the script only targets one player and not all players hasanchik 49 — 4y
0
BUT i have to do the CHECK to make sure the script only targets one player and not all players hasanchik 49 — 4y
0
IT WILL STILL WORK User#30567 0 — 4y
0
BUT then everyone wont be able to control their character for like 5 seconds hasanchik 49 — 4y
View all comments (3 more)
0
DID YOU TRY User#30567 0 — 4y
0
Ok i will hasanchik 49 — 4y
0
i tried, but it didnt even work at all hasanchik 49 — 4y

Answer this question