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

Passing player through RemoteEvent not working correctly?

Asked by 4 years ago
Edited 4 years ago

Henlo. :3 What I'm trying to do is give a player through a remoteevent, which I know how to do, but it doesn't seem to be working correctly. The remoteevent, localscript and script are in the backpack of the player, which shouldn't be an issue either.

Here's the script for the localscript:

plr = game.Players.LocalPlayer
mouse = plr:GetMouse()
tool = script.Parent
equipped = false
active = false

tool.Equipped:connect(function()
    equipped = true
    mouse.Button1Down:connect(function()
        if equipped and not active then
            local target = mouse.Target
            if target.Parent:FindFirstChild("Humanoid") then
                active = true
                local targetPlayer = game.Players:FindFirstChild(target.Parent.Name)
                local newUI = script:WaitForChild("CitationGUI_Officer"):Clone()
                newUI.Main.Title.Convicted.Text = "Convicted: " ..targetPlayer.Name
                newUI.Parent = plr.PlayerGui
                newUI.Main.Actions:WaitForChild("Submit").MouseButton1Down:connect(function()
                            if newUI.Main.Reason:WaitForChild("TextBox").Text ~= "" then
                                script.CitiaionGiver.Event:FireServer(targetPlayer)
                                newUI:Destroy()
                                active = false
                            else
                          end
                       end)
                newUI.Main:WaitForChild("IconCloseButton").MouseButton1Down:connect(function()
                    newUI:Destroy()
                    active = false
                end)
            end
        end
    end)    
end)

tool.Unequipped:connect(function()
    equipped = false
end)

And the script for the script:

script.Event.OnServerEvent:Connect(function(e)
    script.TargetName.Value = e.Name
    local PnewUI = script.Parent:WaitForChild("CitationGUI_Player"):Clone()
    PnewUI.Main.Title.Convicted.Text = "By: " ..script.TargetName.Value
    PnewUI.Parent = game.Players[script.TargetName.Value].PlayerGui
    PnewUI.Enabled = true
end) --I'm using a stringvalue because passing the player through normally didn't seem to work, I don't plan for it to stay like this :P

Sorry if this is a basic question, any help is appreciated! ^w^

(but if you need some context, what I'm trying to make is a citation notepad where you can cite people, the gui for the player works fine but giving the "you've been cited" message seems to just give it to the player who has the notepad, which it isn't meant to do, if you could find another way to give the gui that would work too :3)

0
What script doesnt work local or server script. And what line does it not work? JesseSong 3916 — 4y
0
I'm pretty sure it's the server script, it gives the gui to the wrong player. And to reiterate the script works, but not in an intended way. "but what I'm trying to make is a citation notepad where you can cite people, the gui for the player works fine but clicking the "submit" button seems to just give it to the player who has the notepad, which it isn't meant to do." iOriena3 67 — 4y

3 answers

Log in to vote
1
Answered by
Leamir 3138 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

Hello, iOriena2!

We'll only change your server script:

script.Event.OnServerEvent:Connect(function(sender, e) -- Local script event will aways send the local player as first argument
    script.TargetName.Value = e.Name
    local PnewUI = script.Parent:WaitForChild("CitationGUI_Player"):Clone()
    PnewUI.Main.Title.Convicted.Text = "By: " ..script.TargetName.Value
    PnewUI.Parent = game.Players[script.TargetName.Value].PlayerGui
    PnewUI.Enabled = true
end) --I'm using a stringvalue because passing the player through normally didn't seem to work, I don't plan for it to stay like this :P

Hope this fixes your issue.

You should aways name your variables with names that remember you what they store, like in that example, it should be something that remembers "citation"

If you need any more help, post a comment on this topic, message or add me on Roblox

0
yay it works :D thank u so much c: iOriena3 67 — 4y
Ad
Log in to vote
-1
Answered by 4 years ago

ok so your serverscript seems to havethegay, so let's fix that, youstupidhomosexualfemale. So first you need to use a pcall function in order tore-write and clone the player so that they go up someone'sAnus and then we must milkyourmom.

local pcall = game.print("you'reAFuckingFag")
script.Event.OnServerEvent:Connect(function(sender, e)
    script.TargetName.Value = e.Name
    local PnewUI = script.Parent:WaitForChild("CitationGUI_Player"):Clone()
    PnewUI.Main.Title.Convicted.Text = "By: " ..script.TargetName.Value
    PnewUI.Parent = game.Players[script.TargetName.Value].PlayerGui
    PnewUI.Enabled = true
end) 

wait(69)

print("orienaHasSTDS")--this is to ensure the script is functioning

if that was too difficult for yourfeeblefemale mind to understand, please go give birth to another littleshit or whatever it is you do in your free time.

0
wow... iOriena3 67 — 4y
Log in to vote
-2
Answered by 4 years ago

This might help:

script:

plr = game.Players.LocalPlayer
mouse = plr:GetMouse()
tool = script.Parent
equipped = false
active = false

tool.Equipped:connect(function()
    equipped = true
    mouse.Button1Down:connect(function()
        if equipped and not active then
            local target = mouse.Target
            if target.Parent:FindFirstChild("Humanoid") then
                active = true
        local players = game:GetService("Players"):GetPlayers()
        for _,player in pairs(players) do -- changed here
            if player.Name:lower() == target.Parent.Name:lower() then
             local targetPlayer = player    
            end
        end

                local newUI = script:WaitForChild("CitationGUI_Officer"):Clone()
                newUI.Main.Title.Convicted.Text = "Convicted: " ..targetPlayer.Name
                newUI.Parent = plr.PlayerGui
                newUI.Main.Actions:WaitForChild("Submit").MouseButton1Down:connect(function()
                            if newUI.Main.Reason:WaitForChild("TextBox").Text ~= "" then
                                script.CitiaionGiver.Event:FireServer(targetPlayer)
                                newUI:Destroy()
                                active = false
                            else
                          end
                       end)
                newUI.Main:WaitForChild("IconCloseButton").MouseButton1Down:connect(function()
                    newUI:Destroy()
                    active = false
                end)
            end
        end
    end)    
end)

tool.Unequipped:connect(function()
    equipped = false
end)
0
that doesn't seem to do much, all it does now is copy the "cited" gui to the player who clicked submit, and not the player that was clicked. which is whats meant to happen iOriena3 67 — 4y
0
sorry I ges marine5575 359 — 4y
0
Im having troble figuring out what you need help with, could you please explain it more? marine5575 359 — 4y
0
I thought I made that pretty clear ,_, but what I'm trying to make is a citation notepad where you can cite people, the gui for the player works fine but clicking the "submit" button seems to just give it to the player who has the notepad, which it isn't meant to do, it's meant to give it to the player that was clicked at the start of the script. iOriena3 67 — 4y
View all comments (2 more)
0
oh, so like a gui pops up to a player that the player with the tool clicked on? marine5575 359 — 4y
0
yup, exactly :3 iOriena3 67 — 4y

Answer this question