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

How to pass the player value in a bindable event?

touched script

script.Parent.Touched:Connect(function()
	local Players = game.Players
	local part = script.Parent
	local player = Players:GetPlayerFromCharacter(part.Parent)
	game.ReplicatedStorage:WaitForChild("PurchaseZone"):Fire(player,script.Parent.Name,10)
end)

I am working on a game, i am trying to pass the player who touched a certain brick to another script but it returns a nil value, i tried getplayerfromcharacter but no success, any other methods?

receiver

game.Players.PlayerAdded:Connect(function(Player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = Player
	local zones = Instance.new('Folder')
	zones.Name = "Zones"
	zones.Parent = Player
	local candy = Instance.new("IntValue")
	candy.Name = "Candy"
	candy.Parent = leaderstats 
	candy.Value = 10
	local currenttool = Instance.new("Folder")
	currenttool.Name = "CurrentTool"
	currenttool.Parent =Player
	local testzone = Instance.new("StringValue")
	testzone.Name = "Partt"
	testzone.Value = "Partt"
	testzone.Parent = zones
end)

game.ReplicatedStorage.PurchaseZone.Event:Connect(function(player,zone,cost)
if player.Zones:GetChildren().Name ~= zone and player.leaderstats.Candy.Value >= cost then
		local zoneadded = Instance.new("StringValue")
		zoneadded.Parent = player.Zones
		zoneadded.Name = zone
		zoneadded.Value = zone
     end
end)

6 comments

0

how are you passing it? and it would probably be beneficial to see some code

0

edit the question put both scripts in a code block

0

done

0

closer, but it's not a code block..play around with the buttons until you see code block and then paste it into that

0

there you go, sorry, new to this website

0

No worries

1 answer

✓ Accepted answer

I've made some changes, you are trying to get the character from script.Parent but instead you should be using the parent of the touching part itself given from the Touched event

script.Parent.Touched:Connect(function(part) 
	local Players = game.Players 
	local player = Players:GetPlayerFromCharacter(part.Parent)
	if player then
		game.ReplicatedStorage:WaitForChild("PurchaseZone"):Fire(player,script.Parent.Name,10) 
	end
end)

3 comments

1

i did try the If player part, ill try this now thanks!

0

if player will prevent it from sending a nil value

1

Yeah, when i tried if player with my code it did nothing obviously, this worked thanks!

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