I’m trying to put a clickDetector inside of the player. When another player clicks on them, I want it to open a Gui.
I’ve tried to figure it out myself, but I ran in to a variety of issues.
Thanks!
Let me know if you need any more information.
I’m trying to put a clickDetector inside of the player. When another player clicks on them, I want it to open a Gui.
I’ve tried to figure it out myself, but I ran in to a variety of issues.
Thanks!
Let me know if you need any more information.
Can we see the part of the script containing the errors, or all of it?
Every script I’ve tried so far has not worked. However, none of them produced any errors. I finally gave up and came here.
Here’s one of the scripts I tried:
local players = game:GetService("Players")
local clickadd = Instance.new("ClickDetector")
players.PlayerAdded:Connect(function(player)
clickadd.parent = player.UpperTorso
end)
clickadd.MouseClick:Connect(function(plr)
end)
What type of script is this, and what code are you executing in the MouseClick event?
This is a normal script in ServerScriptService.
I plan on executing something like this:
game.ReplicatedStorage.Race:Clone().Parent = plr
You should clone the ClickDetector before parenting or instance a new one each time. Currently, your ClickDetector is going into one player, and then being moved to a different player each time a player joins. Also, you’re putting it into the Player instead of the Player’s Character.
Would you mind providing a code example?
You can’t place any object in the player’s character rigs. Instead place it on the player’s HumanoidRootPart
.
(You can actually place a object into player’s rig. But this must be a custom character)
Current script:
local players = game:GetService("Players")
local clickadd = Instance.new("ClickDetector")
players.PlayerAdded:Connect(function(player)
clickadd:Clone().parent = player.HumanoidRootPart
end)
clickadd.MouseClick:Connect(function(plr)
end)
Reference to @MightyDantheman
Make it
players.PlayerAdded:Connect(function(player)
local clickadd = Instance.new("ClickDetector")
clickadd.Parent = player.Character.HumanoidRootPart
--- puting just player will just return nil as theres no children/ properties on the player do put .Character
local function ClickedPlayer(user)
-- the user is for the person who clicked it.
user:WaitForChild("PlayerGui"):WaitForChild("YourGuiHere", 45).Enabled = true
end
clickadd.MouseClick:Connect(ClickedPlayer)
end)
Instead cause it will just create 1 instance when the server was started
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
local clickadd = Instance.new("ClickDetector")
clickadd:Clone().parent = player.HumanoidRootPart
end)
clickadd.MouseClick:Connect(function(plr)
--bleh
end)
This should work.
Also does this need to be server-side, or can it be client-side?
If it does need to be server-side, it should be:
local Players = game:GetService('Players')
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local click = Instance.new('ClickDetector',character:WaitForChild('HumanoidRootPart'))
click.MouseClick:Connect(function(plr)
print(plr)
end)
end)
end)
It doesn’t need to be server sided. It just needs to work.
also, this didn’t work. There’s nothing in the output for some reason.
It didn’t work. Here’s the error:
HumanoidRootPart is not a valid member of Player "Players.CbrahDev" - Server - Script:5
It did not work because that is not the character. That is just the array of the player. Try adding .Character
and also i updated the script
I know, I was just asking if they needed it to be server-side as this seems more like a client-side situation.
Once again, I can do client-side, or serverside.
I’m talking about the code I wrote.