Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make a script that puts a name inside the Owner value when touched?

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..

2 answers

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.

2 comments

0

Hi. No luck sadly..

0

It doesnt seem to want to change the Owner string.

This discussion is preserved as it was. New answers, comments, and votes are closed.