Alright folks, here I am once again asking for help… I’m currently trying to do a script that just changes the Value Text to change to the player name but once again I’m too stupid to do it… if you know what I did wrong please correct me and tell me what needs to be changed thanks
local Player = game.Players.LocalPlayer --Get the player's character here
local part = script.Parent
local Players = game:GetService("Players")
if script.Parent.Parent.Owner.Value == nil then
end
local function OnTouched(player)
part.Touched:Connect(function(hit)
local Player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
local name = player.name
script.Parent.Owner.Value = name
script.Parent.Touched:Connect(OnTouched)
end
end)
end
Welp it’s gonna be 1 of those posts now isn’t it
I’ll go ahead and explain it: If this is on a Server Script you cannot get the Local Player
that way, it just isn’t possible for the server to detect which specific Player
you’re exactly looking for
Why are you connecting the Event inside the function? It won’t even be able to fire since it’ll only activate when it’s called by something
Here’s a fixed version with some print()
debugs:
--local Player = game.Players.LocalPlayer (J u s t n o)
local part = script.Parent
local Players = game:GetService("Players")
if script.Parent.Parent.Owner.Value == nil then --No clue why you have this here
end
local function OnTouched(hit)
print("Touched")
local Player = Players:GetPlayerFromCharacter(hit.Parent)
if Player then
print("Changed stuff!")
local name = Player.name
script.Parent.Owner.Value = name
end
end
part.Touched:Connect(function(OnTouched)
2 Likes
Alrighty, thank you for the quick response! As you probably can tell with closed eyes I’m really new to the whole scripting stuff, I’m used to just editing peoples stuff to get it to work again. And because you asked I did the whole
if script.Parent.Parent.Owner.Value == nil then
to make sure if another player is touching the part he wont be the new “owner” but I guess it wasn’t the best thing or whatever it just sounded right.
Ah, so what you could do is put that if statement
inside the function when the part gets touched
(It took me a while to understand what you were trying to say)
--local Player = game.Players.LocalPlayer (J u s t n o)
local part = script.Parent
local Players = game:GetService("Players")
part.Owner.Value = nil
--No clue why you have this here
end
local function OnTouched(hit)
print("Touched")
if part.Owner.Value ~= nil then
return
end
local Player = Players:GetPlayerFromCharacter(hit.Parent)
if Player then
print("Changed stuff!")
local name = Player.name
part.Owner.Value = name
end
end
part.Touched:Connect(function(OnTouched)
1 Like