New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

When I fire the server my value changes somehow? How do I fix that?

Asked by
popeeyy 488 Moderation Voter
2 years ago

I am making a hotel system and when I try to fire the server with a player, it sends the right player value but the other script prints out a different one. So it sent the name "dyslexia1" but the script got it as "poppeyhead" Any way to fix? Also, FE is on. Starter Gui Script:




script.Parent.FocusLost:connect(function(enterPressed) if enterPressed then local count = 0 local plr = nil for i,v in next, game.Players:GetChildren() do if string.len(v.Name) >= string.len(script.Parent.Text) then if string.lower(script.Parent.Text) == string.lower(string.sub(v.Name,0,string.len(script.Parent.Text))) then count = count+1 plr = v print(v.Name) end end end if count == 1 and game.Players.LocalPlayer.Name ~= plr.Name then script.Parent.Text = "Name :)" local giver= game.Players.LocalPlayer game.ReplicatedStorage.RoomSystem.Events.CheckIn:FireServer(plr) print(plr.Name) script.Parent.Parent.Parent.Waiting.Visible=true script.Parent.Parent.Visible=false wait (1) script.Parent.Parent.Parent.Parent:Destroy() end end end)

SSS Script:

game.ReplicatedStorage.RoomSystem.Events.CheckIn.OnServerEvent:connect(function(plr)
    pcall(function()
        print(plr.Name)
local target= plr
local rooms= game.ReplicatedStorage.RoomSystem.Rooms
local keys= game.ReplicatedStorage.RoomSystem.Keys
local room1= rooms:FindFirstChild("Room 1")
local room2= rooms:FindFirstChild("Room 2")
local room3= rooms:FindFirstChild("Room 3")
local room4= rooms:FindFirstChild("Room 4")
local room5= rooms:FindFirstChild("Room 5")
local key1= keys:FindFirstChild("Room 1")
local key2= keys:FindFirstChild("Room 2")
local key3= keys:FindFirstChild("Room 3")
local key4= keys:FindFirstChild("Room 4")
local key5= keys:FindFirstChild("Room 5")
print("HI")

if target ~= nil then
    print("Target not nil")
    if target.CheckOut.Value==true then
        print("running")
        target.CheckOut.Value= false
        target.CheckIn.Value= true
        if room1.Value== false then
            room1.Value= true
            target.Room.Value= 1


        local key= key1:Clone()
        key.Parent= plr.Backpack

            elseif room2.Value==false then
            room2.Value= true
            target.Room.Value= 2
                local key= key2:Clone()
        key.Parent= plr.Backpack



                elseif room3.Value==false then
                room3.Value= true
                target.Room.Value= 3

            local key= key3:Clone()
        key.Parent= plr.Backpack

                    elseif room4.Value==false then
                    room4.Value= true
                    target.Room.Value= 4
                        local key= key4:Clone()
        key.Parent= plr.Backpack



                        elseif room5.Value==false then
                        room5.Value= true
                        target.Room.Value= 5

            local key= key5:Clone()
        key.Parent= plr.Backpack

        end


    end
end
end)
end)

1 answer

Log in to vote
0
Answered by 2 years ago

This is because automatically, the first argument of OnServerEvent is the player who fired the remote. So, you just need to put the place where it sends the player who fired the remote to a different variable. For example, you could do

game.ReplicatedStorage.RoomSystem.Events.CheckIn.OnServerEvent:connect(function(_, plr)
    pcall(function()
        print(plr.Name)
local target= plr
local rooms= game.ReplicatedStorage.RoomSystem.Rooms
local keys= game.ReplicatedStorage.RoomSystem.Keys
local room1= rooms:FindFirstChild("Room 1")
local room2= rooms:FindFirstChild("Room 2")
local room3= rooms:FindFirstChild("Room 3")
local room4= rooms:FindFirstChild("Room 4")
local room5= rooms:FindFirstChild("Room 5")
local key1= keys:FindFirstChild("Room 1")
local key2= keys:FindFirstChild("Room 2")
local key3= keys:FindFirstChild("Room 3")
local key4= keys:FindFirstChild("Room 4")
local key5= keys:FindFirstChild("Room 5")
print("HI")

if target ~= nil then
    print("Target not nil")
    if target.CheckOut.Value==true then
        print("running")
        target.CheckOut.Value= false
        target.CheckIn.Value= true
        if room1.Value== false then
            room1.Value= true
            target.Room.Value= 1


        local key= key1:Clone()
        key.Parent= plr.Backpack

            elseif room2.Value==false then
            room2.Value= true
            target.Room.Value= 2
                local key= key2:Clone()
        key.Parent= plr.Backpack



                elseif room3.Value==false then
                room3.Value= true
                target.Room.Value= 3

            local key= key3:Clone()
        key.Parent= plr.Backpack

                    elseif room4.Value==false then
                    room4.Value= true
                    target.Room.Value= 4
                        local key= key4:Clone()
        key.Parent= plr.Backpack



                        elseif room5.Value==false then
                        room5.Value= true
                        target.Room.Value= 5

            local key= key5:Clone()
        key.Parent= plr.Backpack

        end


    end
end
end)
end)

Hope this helps!

0
Thanks, NOW it works! I spent an hour on this because this is my second time using remote events so I dunno what I'm doing. popeeyy 488 — 2y
Ad

Answer this question