Hi. Basically I have a part which is spawned from Lighting.
Inside the part in Lighting, it has a StringValue called Owner.
How would I make it so that when the part is touched, it changed the Owner value to a name?
This is the script inside the part:
de = false function OnClick(hit) if game.Players:GetPlayerFromCharacter(hit.Parent) and de == false then de = true local a = game.Lighting.Storage.Dew:clone() a.Owner.Value = hit.Parent print (hit.Parent) end wait(2) de = false end script.Parent.ClickDetector.MouseClick:connect(OnClick) script.Parent.Touched:connect(OnClick)
The item also has a ClickDetector. Weirdly, it detects me in the print command, but doesn't put my name in the Owner value..
It is because you wanna get the Name
property, as it is a string, whilst the player itself is an Instance
. Here is how your script will look like:
local de = false function OnClick(hit) if game.Players:GetPlayerFromCharacter(hit.Parent) and de == false then de = true local a = game.Lighting.Storage.Dew:clone() a.Owner.Value = hit.Parent.Name -- references the name print (hit.Parent) end wait(2) de = false end script.Parent.ClickDetector.MouseClick:Connect(OnClick) script.Parent.Touched:Connect(OnClick)
Also not sure why you put things inside Lightning, I mean, that's why ServerStorage and ReplicatedStorage exists.