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

Why is this trail giver button's script only working in Testplay Mode, and not in server modes?

Longtime ROBLOX user who has just started scripting.

Working on a script that when a button is touched, it gives a player a trail. The code itself isn't in a local script, it's in a regular script and it works in test > play mode. I tried to move it to a local script, but then the script doesn't work.

I've been tinkering/researching with this for a few hours with no luck, would anyone be able to help me fix this? Thank you.

wait(1)
function onTouched(hit)
	wait(1)
	if not game.Players.LocalPlayer.Character.LowerTorso:FindFirstChild("FairyMagicTrail") then
	local ReplicatedStorage = game:GetService("ReplicatedStorage")
local trail = ReplicatedStorage.BloomMythixTrail:Clone()
trail.Parent = game.Players.LocalPlayer.Character.LowerTorso
	local attachment0 = game.Players.LocalPlayer.Character.UpperBody.Left1.Attachment1
	local attachment1 = game.Players.LocalPlayer.Character.UpperBody.Right2.Attachment1
	trail.Attachment0 = attachment0
	trail.Attachment1 = attachment1
	end
	if game.Players.LocalPlayer.Character.LowerTorso:FindFirstChild("FairyMagicTrail") then
		end
	end
script.Parent.Touched:connect(onTouched)

2 comments

0

Localplayer only exists in localscripts(and they must be inside the player) when running in online mode.

0

What's the workaround for that? Is there something else I can call to find the character that is stepping on the brick?

1 answer

Get the player who touched by using the "hit" argument you've put

function onTouched(hit)
	wait(1)
	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if Player then
		if not Player.Character:FindFirstChild("BloomMythixTrail") then
			local ReplicatedStorage = game.ReplicatedStorage
			local trail = ReplicatedStorage.BloomMythixTrail:Clone()
			trail.Parent = Player.Character.LowerTorso
			local attachment0 = Player.Character.UpperBody.Left1.Attachment1
			local attachment1 = Player.Character.UpperBody.Right2.Attachment1
			trail.Attachment0 = attachment0
			trail.Attachment1 = attachment1
		end
	end
end
script.Parent.Touched:Connect(onTouched)

the reason it only worked in studio when using LocalPlayer is that when you're testing inside of studio, you can see in the properties of game.Players, that you are always the local player inside of studio.

2 comments

0

Thank you so much! This makes much more sense and I appreciate your help. If I had reputation on this site, I would definitely give your reply a thumbs up!

0

You're welcome. You could help me by clicking the "Accept Answer" button below my reply.

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